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
  • 相关阅读:
    五子棋项目
    判断是否是素数
    双链表
    九九乘法表
    栈和队列
    c排序
    蓝桥杯 接水问题 模拟
    蓝桥杯 调和数列问题
    蓝桥杯 Hanoi问题 递归
    蓝桥杯 排列问题
  • 原文地址:https://www.cnblogs.com/myjacky/p/3713148.html
Copyright © 2011-2022 走看看