您的位置:首页 > 其它

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

2014-05-15 11:27 555 查看
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 ,可以对指定表,更新所有相关的统计信息。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐