惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 破曉之陽

SQL 查找某年某月的天数 SQL操作全集 因为没工作了。所以的复习一下以前的东西。好去面试 SQL Server性能优化 应用Profiler优化SQL Server数据库系统 SQL CASE - 破曉之陽 - 博客园 SQL EXISTS - 破曉之陽 - 博客园 SQL 刪除相同的記錄 SQL left,RIGHT,CHARINDEX 使用示例 80048820 - 破曉之陽 - 博客园 奇怪的问题。 - 破曉之陽 - 博客园 如何在 Windows 2000 中提升和降级域控制器 Microsoft.Exchange.OMA.PreferencingServerResources.Resources.dll.EN 指定的網域的名稱或安全性識別碼(用磁碟映像檔部署的電腦無法加入AD網域 ) Microsoft.NET框架程序设计(修订版) 下载地址 将这个字段中所有含‘北京’的替换成'上海' 电脑自动重启 演练:使用受保护的配置加密配置信息 vs c#2005 web编程中的.cs文件为什么都没有namespace?
创建触发器和使用示例(于海涛 老师的实验课)
破曉之陽 · 2008-06-06 · via 博客园 - 破曉之陽

1、数据表的建立

use login

create table voteMaster   -----主表
(
voteId int primary key,    --编号
voteTitle varchar(100) not null,   ---投票的项目
voteSum int default 0   --总票数,默认为0
)
insert into voteMaster values(1,'选举工会主席',0)
insert into voteMaster values(2,'对网站的建议',0)

create table voteDetails    ---从表
(
voteId int foreign key references voteMaster(voteId),----外键 约束
voteDetailsId int not null,
voteItem varchar(20) not null,
votNum int default 0,
primary key(voteId,voteDetailsId)          ----连合主键
)

insert into voteDetails values(1,1,'于海涛',0)
insert into voteDetails values(1,2,'王小刚',0)
insert into voteDetails values(1,3,'张老三',0)

insert into voteDetails values(2,1,'非常好',0)
insert into voteDetails values(2,2,'好',0)
insert into voteDetails values(2,3,'一般',0)
insert into voteDetails values(2,4,'需要改进',0)

2、触发器的创建

create trigger updateMaster   -----创建触发器
on voteDetails     -----触发器所建的表
for update         -----触发器的条件
as
begin
           update voteMaster set voteSum=voteSum+1 where voteId=(select top 1 voteid from inserted)
end

最终效果:

你只要对voteDetails 内votNum的数据进行更新,那么主表voteMaster 的voteSum就会加1,从而实现了对投票的总数的统计的实现。

注意:    select top 1 voteid from deleted

         inserted表   deleted表
insert 新插入的行
update 数据库受到影响的行在更新之后的新值 数据库受到影响的行在更新之前的旧值
delete 删除的行

当你想自动更新数据库的时候 无论数据库怎样更新,插入新数据也好,自动在后面添加你想添加的东西


create trigger trig_notic_UI
on notic for insert,update
as
update notic set memo=memo+'<dcboy>'
where id in(select id from inserted)
go

/*
trig_notic_UI   触发器名称 自定义
notic 需要触发的表名
memo 需要更新的字段
id   是主键
*/