zoukankan      html  css  js  c++  java
  • Sql Server数据库笔记

    1:增加外键

    drop table TeacherUser

    create table TeacherUser
    (
        Id int identity(1,1) primary key not null,
    Name nvarchar not null,
    studentID int not null
    foreign key (studentID) references testDB.[dbo].[StudentUser](id)
    )


    alter table testDB.[dbo].TeacherUser

    add constraint keyword foreign  key(studentID) references testDB.[dbo].[StudentUser](id)



    --更新门票触发器
    create trigger tgr_update_admissionstatus
    on [dbo].[AdmissionTicketProduct] for update
    as
      if(update(Status))
      begin
       declare @status int;
       declare @productId int;
       select @status=inserted.status,@productId=inserted.ID from inserted
       if(@status=2)
         update [dbo].[SpecialProduct] set status=1 where ProductId=@productId and ProductType=16
    else
    update [dbo].[SpecialProduct] set status=2 where ProductId=@productId and ProductType=16
      end
     go


    --创建线路触发器
    create trigger tgr_update_linestatus
    on [dbo].TourProduct for update
    as
      if(update(Status))
      begin
       declare @status int;
       declare @productId int;
       select @status=inserted.status,@productId=inserted.ID from inserted
       if(@status=64)
         update [dbo].[SpecialProduct] set status=1 where ProductId=@productId and (ProductType=1 or ProductType=2)
    else
    update [dbo].[SpecialProduct] set status=2 where ProductId=@productId and (ProductType=1 or ProductType=2)
      end
     go


     --创建酒店触发器
     create trigger tgr_update_Hotelstatus
    on [dbo].HotelProduct for update
    as
      if(update(Status))
      begin
       declare @status int;
       declare @productId int;
       select @status=inserted.status,@productId=inserted.ID from inserted
       if(@status=2)
         update [dbo].[SpecialProduct] set status=1 where ProductId=@productId and ProductType=4
    else
    update [dbo].[SpecialProduct] set status=2 where ProductId=@productId and ProductType=4
      end
     go


     --创建机票触发器
    create trigger tgr_update_flightstatus
    on [dbo].AirTicket for update
    as
      if(update(Status))
      begin
       declare @status int;
       declare @productId int;
       select @status=inserted.status,@productId=inserted.ID from inserted
       if(@status=2)
         update [dbo].[SpecialProduct] set status=1 where ProductId=@productId and ProductType=8
    else
    update [dbo].[SpecialProduct] set status=2 where ProductId=@productId and ProductType=8
      end
     go

  • 相关阅读:
    Atitit 趋势管理之道 attilax著
    Atitit 循环处理的新特性 for...else...
    Atitit 2017年的技术趋势与未来的大技术趋势
    atitit 用什么样的维度看问题.docx 如何了解 看待xxx
    atitit prj mnrs 项目中的几种经理角色.docx
    Atitit IT办公场所以及度假村以及网点以及租房点建设之道 attilax总结
    Atitit 工具选型的因素与方法 attilax总结
    Atitit.团队文化建设影响组织的的一些原理 法则 定理 效应 p826.v4
    Atiitt 管理方面的误区总结 attilax总结
    Atitit 未来趋势把控的书籍 attilax总结 v3
  • 原文地址:https://www.cnblogs.com/wangyhua/p/4050588.html
Copyright © 2011-2022 走看看