SQL Server 触发器
来源:互联网 发布:lg v20 跳过网络验证 编辑:程序博客网 时间:2024/06/10 04:15
在学习牛腩的时候我第一次正式在SQL Server 实现了触发器,他与存储过程很相似,可以说触发器是一种特殊类型的存储过程,但触发器主要是通过事件进行触发被自动调用执行的,而存储过程可以通过存储过程的名称被调用。
1,创建触发器
<span style="font-size:18px;">-- ================================================-- Template generated from Template Explorer using:-- Create Trigger (New Menu).SQL---- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below.---- See additional Create Trigger templates for more-- examples of different Trigger statements.---- This block of comments will not be included in-- the definition of the function.-- ================================================SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:<Author,,Name>-- Create date: <Create Date,,>-- Description:<Description,,>-- =============================================CREATE TRIGGER trigCategoryDelete ON category instead of DELETEAS BEGINdeclare @caID intselect @caID=id from deleted--删除评论delete comment where newsId in (select newsId from news where caID =@caID )--删除新闻delete news where caID=@caID --删除新闻类别delete category where id=@caID ENDGO</span>
2,修改触发器
<span style="font-size:18px;">USE [newssystem]GO/****** Object: Trigger [dbo].[trigCategoryDelete] Script Date: 06/10/2015 16:48:45 ******/SET ANSI_NULLS ONGOSETQUOTED_IDENTIFIER ONGO--=============================================--Author: tsj-- Create date: 2015年6月9日16:40:00--Description: 删除类别触发器--=============================================ALTER TRIGGER[dbo].[trigCategoryDelete] ON [dbo].[category] AFTER deleteAS BEGIN--select* from deleteddeclare @caId int ---定义变量select @caId=id from deleted -----从 deleted中取出id--删除评论deletecomment where newsId=(select newsId from news where caID=@caId) --删除新闻deletenews where caID=@caID --删除类别deletecategory where id=@caID END</span>
3,删除触发器:
<span style="font-size:18px;">drop trigger trigger_name </span>
1 0
- 【sql server】SQL触发器
- SQL-SERVER触发器
- SQL Server触发器
- Ms SQL Server 触发器
- sql server:触发器
- sql server 触发器
- SQL Server创建触发器
- SQL Server触发器
- SQL Server创建触发器
- SQL Server创建触发器
- Sql Server 触发器(二)
- sql-server 简单触发器
- SQL SERVER 触发器-实例
- SQL Server中的触发器
- SQL Server 触发器
- SQL Server触发器
- SQL Server 触发器
- SQL SERVER触发器实现
- [Android]可缩放性ImageView(可以放大缩小)
- NSArray / NSMutableArray
- oracle里面base64加解密
- LeetCode219——Contains Duplicate II
- PCA原理以及算法实现
- SQL Server 触发器
- ftp 限定用户不可以离开主目录
- NSMutableArray(可变数组)
- RF 缩写,方便以后查找
- 使用命令npm install -g hexo-cli 安装Hexo报错问题
- EL和OGNL (转)
- NSDictionary /NSMutableDictionary
- redis3.0.3集群安装详细步骤
- 3021: Supermarket