• 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
  • 相关阅读:
    7.21
    7.14
    7.7
    大学生失物招领平台使用体验及改进意见
    cdh集群迁移 ip更改
    klearn.preprocessing.PolynomialFeatures学习
    二元线性回归
    python学习之numpy.ewaxis
    sklearn.linear_model.LinearRegresion学习
    一元线性回归-梯度下降法-房价预测
  • 原文地址:https://www.cnblogs.com/myjacky/p/3713148.html
Copyright © 2020-2023  润新知