Export (0) Print
Expand All

Table.Checks Property

Represents a collection of Check objects. Each Check object represents a check constraint defined on the table.

Namespace:  Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

[SfcObjectAttribute(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, 
	typeof(Check), SfcObjectFlags.Design)]
public CheckCollection Checks { get; }

Property Value

Type: Microsoft.SqlServer.Management.Smo.CheckCollection
A Check object that represents all the check constraints that are defined on the table.

The following code example shows how to display the names of each check constraint on each AdventureWorks2012 table.

C#

Server srv = new Server("(local)");
Database db = srv.Databases["AdventureWorks2012"];

foreach (Table tb in db.Tables)
{
   foreach (Check ck in tb.Checks)
   {
      Console.WriteLine("The " + tb.Name + " table has the " + ck.ToString() + " check.");
   }
}

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $srv.Databases.Item("AdventureWorks2012")

Foreach ($tb in $db.Tables)
{
   Foreach ($ck in $tb.Checks)
   {
      Write-Host "The" $tb.Name "table has the" $ck "check."
   }
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft