sql 触发器使用例子
网络编程 2021-07-05 13:42www.168986.cn编程入门
触发器里没有updated ,只有inserted 和deleted两个临时表。
inserted,deleted是在触发器中使用的两个临时表,当执行insert操作时,在inserted中存储着当前插入的记录,在执行delete操作时,在deleted中存储着当前删除的记录,当执行update时,在inserted中存储着修改后的记录,在deleted中存储着修改前的记录。
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [dnt_user_add]
ON [dbo].[dnt_users]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
insert into [dnt_userfields](uid)
select uid from inserted
END
删除
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dnt_users_del]
ON [dnt_users]
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON;
delete [dnt_userfields] from deleted where [dnt_userfields].uid=deleted.uid
END
GO
修改
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dnt_users_up]
ON [dnt_users]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE [dnt_userfields] Set icq = inserted.uid from inserted where [dnt_userfields].uid = inserted.uid
END
GO
代码如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [dnt_user_add]
ON [dbo].[dnt_users]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
insert into [dnt_userfields](uid)
select uid from inserted
END
删除
代码如下:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dnt_users_del]
ON [dnt_users]
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON;
delete [dnt_userfields] from deleted where [dnt_userfields].uid=deleted.uid
END
GO
修改
代码如下:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dnt_users_up]
ON [dnt_users]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE [dnt_userfields] Set icq = inserted.uid from inserted where [dnt_userfields].uid = inserted.uid
END
GO
上一篇:sql 刷新视图
下一篇:数据库 日期加减处理
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程