关于使用sql server 2008触发器完成修改一张表里一个字段同时修改另一张表的另一字段
CREATETRIGGERUpdateTableonUser_SampleafterupdateASBEGINdeclare@userTypeint--得到更改的字段值s...
CREATE TRIGGER UpdateTable
on User_Sample
after update
AS BEGIN
declare @userType int
--得到更改的字段值
set @userType='2'
--得到表1和表2关联的id,也就是外键,table2的ID
declare @userId int
set @userId = (select userId FROM User_Sample )
-- 更新表2 "
update Users set Usertype=@userType where Users.userId =@userId
END
GO
UPDATE [User_Sample] SET [state] = 'True' WHERE [id] = '2'
((select userId FROM User_Sample 获取的是多个值,求有办法至获取修改的那个字段的id莫? 展开
on User_Sample
after update
AS BEGIN
declare @userType int
--得到更改的字段值
set @userType='2'
--得到表1和表2关联的id,也就是外键,table2的ID
declare @userId int
set @userId = (select userId FROM User_Sample )
-- 更新表2 "
update Users set Usertype=@userType where Users.userId =@userId
END
GO
UPDATE [User_Sample] SET [state] = 'True' WHERE [id] = '2'
((select userId FROM User_Sample 获取的是多个值,求有办法至获取修改的那个字段的id莫? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |