![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Create relationships between entities using SMO in Powershell. Hello, I'm just wondering is there an SMO object which I can use to create relationships between entities? I'm guessing it’s something like Microsoft.SqlServer.Management.Smo.Index or Microsoft.SqlServer.Management.Smo.IndexedColumn. However I’ve been having a play and can't seem to work out what are acceptable Parameters which I can pass; the lack of intellisense is killing me ![]() So effectively I have created two tables with their own PK and all I want to do create a relationship between the AccessPerson and Test tables. Here is my code: # Initialise Pk for AccessPerson. $index = New-Object Microsoft.SqlServer.Management.Smo.Index($apTable, "PK_AccessPerson") $index.IndexKeyType = [Microsoft.SqlServer.Management.Smo.IndexKeyType]: riPrimaryKey$indexedColumn = New-Object Microsoft.SqlServer.Management.Smo.IndexedColumn($index, "AccessPersonID") $index.IndexedColumns.Add($indexedColumn) $apTable.Indexes.Add($index) # Initialise PK for Test. $index = New-Object Microsoft.SqlServer.Management.Smo.Index($testTable, "PK_Test") $index.IndexKeyType = [Microsoft.SqlServer.Management.Smo.IndexKeyType]: riPrimaryKey$indexedColumn = New-Object Microsoft.SqlServer.Management.Smo.IndexedColumn($index, "TestID") $index.IndexedColumns.Add($indexedColumn) $testTable.Indexes.Add($index) How to create referential integrity??? I'm convinced that this must be achievable programmatically so any help would be very much appreciated! Thanks, |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Create relationships between entities using SMO in Powershell. Have a look at the microsoft.sqlserver.management.smo.foreignkey class http://msdn2.microsoft.com/en-us/lib...oreignkey.aspx i haven't got access to a SQL box at the moment so can't test it I'm afraid -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "NJC" wrote: Quote: > Hello, > > I'm just wondering is there an > SMO object which I can use to create relationships between entities? > > I'm guessing it’s something like Microsoft.SqlServer.Management.Smo.Index or > Microsoft.SqlServer.Management.Smo.IndexedColumn. > However I’ve been having a play and can't seem to work out what are > acceptable > Parameters which I can pass; the lack of intellisense is killing me ![]() > > So effectively I have created two tables with their own PK and all I want to > do create a relationship between the AccessPerson and Test tables. Here is > my code: > > # Initialise Pk for AccessPerson. > $index = New-Object Microsoft.SqlServer.Management.Smo.Index($apTable, > "PK_AccessPerson") > $index.IndexKeyType = > [Microsoft.SqlServer.Management.Smo.IndexKeyType]: riPrimaryKey> > $indexedColumn = New-Object > Microsoft.SqlServer.Management.Smo.IndexedColumn($index, "AccessPersonID") > > $index.IndexedColumns.Add($indexedColumn) > > $apTable.Indexes.Add($index) > > > # Initialise PK for Test. > $index = New-Object Microsoft.SqlServer.Management.Smo.Index($testTable, > "PK_Test") > $index.IndexKeyType = > [Microsoft.SqlServer.Management.Smo.IndexKeyType]: riPrimaryKey> > $indexedColumn = New-Object > Microsoft.SqlServer.Management.Smo.IndexedColumn($index, "TestID") > > $index.IndexedColumns.Add($indexedColumn) > > $testTable.Indexes.Add($index) > > How to create referential integrity??? I'm convinced that this must be > achievable programmatically so any help would be very much appreciated! > > Thanks, > |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Create relationships between entities using SMO in Powershell. Hey Rich, Thanks for info (again ). Thats all I needed to get it sorted!Cheers again, "RichS" wrote: Quote: > Have a look at the microsoft.sqlserver.management.smo.foreignkey class > > http://msdn2.microsoft.com/en-us/lib...oreignkey.aspx > > i haven't got access to a SQL box at the moment so can't test it I'm afraid > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "NJC" wrote: > Quote: > > Hello, > > > > I'm just wondering is there an > > SMO object which I can use to create relationships between entities? > > > > I'm guessing it’s something like Microsoft.SqlServer.Management.Smo.Index or > > Microsoft.SqlServer.Management.Smo.IndexedColumn. > > However I’ve been having a play and can't seem to work out what are > > acceptable > > Parameters which I can pass; the lack of intellisense is killing me ![]() > > > > So effectively I have created two tables with their own PK and all I want to > > do create a relationship between the AccessPerson and Test tables. Here is > > my code: > > > > # Initialise Pk for AccessPerson. > > $index = New-Object Microsoft.SqlServer.Management.Smo.Index($apTable, > > "PK_AccessPerson") > > $index.IndexKeyType = > > [Microsoft.SqlServer.Management.Smo.IndexKeyType]: riPrimaryKey> > > > $indexedColumn = New-Object > > Microsoft.SqlServer.Management.Smo.IndexedColumn($index, "AccessPersonID") > > > > $index.IndexedColumns.Add($indexedColumn) > > > > $apTable.Indexes.Add($index) > > > > > > # Initialise PK for Test. > > $index = New-Object Microsoft.SqlServer.Management.Smo.Index($testTable, > > "PK_Test") > > $index.IndexKeyType = > > [Microsoft.SqlServer.Management.Smo.IndexKeyType]: riPrimaryKey> > > > $indexedColumn = New-Object > > Microsoft.SqlServer.Management.Smo.IndexedColumn($index, "TestID") > > > > $index.IndexedColumns.Add($indexedColumn) > > > > $testTable.Indexes.Add($index) > > > > How to create referential integrity??? I'm convinced that this must be > > achievable programmatically so any help would be very much appreciated! > > > > Thanks, > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Create new volume in Powershell | PowerShell | |||
| Managing 2 activesync relationships | .NET General | |||
| Create Printers With Powershell | PowerShell | |||
| Create IIsWebDirectorySetting from PowerShell via WMI | PowerShell | |||
| Better understanding WMP11 and UPNP relationships | Vista networking & sharing | |||