--创建聚集索引 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