|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 5:38 AM
Points: 344,
Visits: 601
|
|
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!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 2:33 PM
Points: 1,090,
Visits: 4,540
|
|
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
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 5:38 AM
Points: 344,
Visits: 601
|
|
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
|
|
|
|