DELETE触发器
CREATE TRIGGER DELUser ON UserInfo--创建一个DELETE触发器
FOR DELETE--定义出发条件
AS
declare @id int
select @id = userid from deleted--临时表deleted,在每次执行删除后生成,获取到被操纵USERID
print '删除成功'
DELETE USERBed WHERE USERBed.USERID = @id--删除相关联的userbed表中对应的数据
INSERT触发器
CREATE TRIGGER ADDUser ON UserInfo--创建一个INSERT触发器
FOR INSERT--定义出发条件
AS
declare @id int
select @id = userid from INSERTED--临时表inserted,在每次执行插入操作后生成,获取到被操纵USERID
print '插入数据成功'
INSERT INTO USERBED VALUES(1,@id)--在相关联的userbed表中插入对应的数据