sql 增加数据的例子
ALTER trigger createPerson on Person
for insert
as
begin
declare @name nchar(10)
select @name=name from inserted
INSERT INTO PersonCopy
(
name
)
VALUES
(
@name
)
print '结果为:
'+@name
--insert into storeInfo(storeID,mID) values((select mID from ))
end
sql 修改数据时的触发器
USE [hh]
GO
/****** 对象: Trigger [dbo].[UpdatePerson] 脚本日期: 05/15/2013 08:58:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[UpdatePerson]
on [dbo].[Person]
for update
as
declare @oldName nchar(10), @newName nchar(10);
--更新前的数据
select @oldName = name from deleted;
if (exists (select name from PersonCopy where
name=@oldName
))
begin
--更新后的数据
select @newName = name from inserted;
update PersonCopy set name = replace(name, @oldName, @newName) where
name=@oldName
;
end
sql 删除触发器
alter TRIGGER DeletePerson ON Person
FOR delete
AS
BEGIN
DECLARE @name nchar(10);
SELECT @name=name FROM deleted
DELETE FROM PersonCopy WHERE
name=@name
end
sql判断触发器是否存在
if (object_id('createPerson', 'TR') is not null)
drop trigger createPerson