SQL Server2008 1

多表触发器
create trigger trg_a
on a表
for update
as
declare @xmbh varchar(10)
select @xmbh=项目编号 from updated
declare @xmmc varchar(50)
select @xmmc=项目名称 from updated
update B表 set 项目名称=@xmmc where 项目编号=@xmbh
update c表 set 项目名称=@xmmc where 任务书编号=@xmbh
go



两表相关联的视图
CREATE VIEW dbo.VIEW3
AS
SELECT dbo.info.*, dbo.login.name AS 姓名, dbo.login.password AS 密码
FROM dbo.info INNER JOIN
      dbo.login ON dbo.info.id = dbo.login.id








declare @did char(3)
    declare @faly char(1)
    declare @employeeid char(6)    
    declare @name char(10)
    declare @birthday datetime
    declare @sex char(2)
    update  updated set @employeeid=employeeid
    select @did=departmentid  from Inserted
    select @faly='1'  from departments where departmentid=@did
if @faly='1'
begin
insert into employees(employeeid,name,birthday,sex,departmentid) values(@employeeid,@name,@birthday,@sex,@did)
end
else
begin
rollback
end
原文地址:https://www.cnblogs.com/qiushuixizhao/p/3138956.html