删除重复值【根据两个字段判断】(只保留一个)&查看执行计划&统计信息

来源:互联网 发布:ui设计师求职知乎 编辑:程序博客网 时间:2024/06/04 18:14

delete  a fromStockPartCodea

where exists

 (select*from(selectStockCode,PartCodefromStockPartCode

 group byStockCode,PartCodehavingcount(*)> 1)b where a.StockCode=b.StockCode

 and a.PartCode=b.PartCode)

and a.StockPartCodeIdnotin(selectmin(StockPartCodeId)fromStockPartCodegroupbyStockCode,PartCodehavingcount(*)>1)

order by StockCode,PartCode

 

//////查看是否使用执行计划http://www.cnblogs.com/WizardWu/p/4052951.html

SELECT cacheobjtype, objtype, usecounts, sql FROM sys.syscacheobjects
WHERE sql  LIKE '%cache%' AND sql NOT LIKE '%sys.%'

///统计信息STATISTICS

统计信息一般系统会自动更新,_WA_Sys开头的是系统自动建立的统计信息,也可给未建索引的列手动创建CREATE STATISTICS,,也可通过 sp_createstats 系統「系统存储过程序(stored procedure)」,直接将数据库的所有表,全部建立统计信息。

执行 UPDATE STATISTICS 指令,可对某个表,或是直接指定索引或「统计」做更新,而 sp_updatestats ,可以对指定表,更新所有相关的统计信息。

0 0