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 ,可以对指定表,更新所有相关的统计信息。