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
  • 相关阅读:
    mark
    ON DUPLICATE KEY UPDATE重复插入时更新
    lnmp上传文件
    websoket
    Nginx 和 Php 优化
    Nginx常见问题
    Keepalived 高可用
    https ; 及https证书
    Nginx动静分离;资源分离;rewrite重写、跳转、伪静态、规则、日志
    nginx负载均衡会话保持;四层负载均衡;端口转发
  • 原文地址:https://www.cnblogs.com/myjacky/p/3713148.html
Copyright © 2011-2022 走看看