【发布时间】:2014-01-30 09:59:28
【问题描述】:
A.有没有可能得到ps-script的结果:
$ss=New-Object Microsoft.SqlServer.Management.Smo.Server 'MyServer';
$ss.Databases[$db].Tables | Where-Object {$_.IsIndexable -eq $true}
与 select 的性能相当
SELECT * FROM sys.Tables WHERE OBJECTPROPERTY(object_id, 'IsIndexable')=1
当然,一种方法是运行 select(来自 ps),然后按名称(或 object_id)实例化一堆 smo.table,例如:
$d = $ss.Databases[$db]
$r = $d.ExecuteWithResults('SELECT object_id FROM sys.tables WHERE OBJECTPROPERTY(object_id, ''IsIndexable'')=1');
$t = @()
foreach ($i in $r.Tables[0].Rows) {$t+=$d.Tables.ItemById($i["object_id"])}
但这看起来不像“它应该是这样的”..
B.如何提高索引过滤器的性能?
$i=$d.Tables.Indexes | where {$_.HasFilter -eq $true};
当然同样的结果也可以通过sql来实现快速:
$d = $ss.Databases[$db]
$r = $d.ExecuteWithResults('SELECT object_id, Name FROM sys.indexes WHERE has_filter=1 ORDER BY object_id, Name');
$t = @()
foreach ($i in $r.Tables[0].Rows) {$t+=$d.Tables.ItemById($i["object_id"]).Indexes[$i["Name"]]}
但我认为应该有更好的解决方案..
【问题讨论】:
标签: sql-server powershell smo