October 10, 2012 at 9:58 am
Is there a way to list the unique table constraints on a given table using smo/powershell?
Or do I have to query the system views?
Thanks!
October 10, 2012 at 3:29 pm
Would something like this work?
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
$s = new-object ("Microsoft.SqlServer.Management.Smo.Server") "SERVERNAME"
$d = $s.Databases | ?{$_.Name -eq "Sandbox"}
$t = $d.Tables | ?{$_.Name -eq "Table1"}
$t.Indexes | ?{$_.IsUnique} | Select Name
- Jeff
October 11, 2012 at 5:10 am
That does get them, but also returns the PK, which in my case I want to ignore.
I was hoping there was some property or combination of properties in SMO.... And I just found it:
$t.Indexes | ? {$_.IndexKeyType -eq "DriUniqueKey"}
Thanks!
Paul
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply