SQL SERVER 触发器示例
触发器是一种特殊的存储过程。
触发器语法 :
CREATE TRIGGER trigger_name ON { table | view } [ WITH ENCRYPTION ]
{ FOR | AFTER | INSTEAD OF } { [ INSERT ] [ DELETE ] [ UPDATE ] }
[ WITH APPEND ] [ NOT FOR REPLICATION ]
AS
sql_statement [ ...n ]
示例:
删除:
DROP TRIGGER auto_guid_trigger
创建:
CREATE TRIGGER auto_guid_trigger ON AUTO_GUID FOR UPDATE AS
IF (SELECT COUNT(GID) FROM AUTO_GUID WHERE LOCKED=0)<1000
BEGIN
DECLARE @ii INT
SET @ii=1
WHILE @ii<=10000
BEGIN
INSERT INTO AUTO_GUID(LOCKED) VALUES(0)
SET @ii=@ii+1
END
END
informix触发器参考:
http://www.blogjava.net/amigoxie/archive/2010/11/05/337363.html