zoukankan      html  css  js  c++  java
  • SQL笔记(1)索引/触发器

    --创建聚集索引
    create clustered index ix_tbl_test_DocDate
    on tbl_test(DocDate)
    with fillfactor=30
    GO
    
    --创建非聚集索引
    create nonclustered index ix_tbl_test_DocNo
    on tbl_test(DocNo)
    with fillfactor=30
    GO
    
    --删除索引
    drop index tbl_test.ix_tbl_test_DocDate
    drop index tbl_test.ix_tbl_test_DocNo
    GO
    
    --创建触发器
    create trigger trg_udf_test_TransLine
    on tbl_test
    for insert,delete,update
    as
        --update
        if exists(select 1 from inserted) and exists(select 1 from deleted)
            update a set a.DocNo=b.DocNo,a.DocLineNo=b.DocLineNo,a.Org=b.Org,a.Wh=b.Wh,a.DocDate=b.DocDate,
            a.ItemInfo_ItemID=b.ItemInfo_ItemID,a.StoreMainQty=b.StoreMainQty,a.Direction=b.Direction
            from tbl_A a
            inner join inserted b on a.ID=b.ID
        --insert
        else if exists(select 1 from inserted)
            insert into tbl_A(ID,DocNo,DocLineNo,Org,Wh,ItemInfo_ItemID,StoreMainQty,DocDate,Direction)
            select ID,DocNo,DocLineNo,Org,Wh,ItemInfo_ItemID,StoreMainQty,DocDate,Direction
            from inserted
        --delete
        else if exists(select 1 from deleted)
            delete from tbl_A where ID in(select ID from deleted)
    GO
    
    --禁用触发器
    alter table tbl_test disable trigger trg_udf_test_TransLine
    
    --启用触发器
    alter table tbl_test enable  trigger trg_udf_test_TransLine
    
    --删除触发器
    drop trigger trg_udf_test_TransLine
    GO
  • 相关阅读:
    司马光 王安石
    辛弃疾
    伯仲叔季
    三国时代
    西汉 东汉 三国(曹魏 蜀汉 东吴)
    数量关系练习题
    为什么不推荐使用外键约束
    Google Map API申请
    Android传感器——加速度传感器
    第三届空间信息智能服务研讨会
  • 原文地址:https://www.cnblogs.com/myjacky/p/3713148.html
Copyright © 2011-2022 走看看