Table.CheckIdentityValue Method ()


Verifies the integrity of all identity columns in the referenced table.

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

public StringCollection CheckIdentityValue()

Return Value

Type: System.Collections.Specialized.StringCollection

A StringCollection system object value that contains the current identity value and the current column value.

This method is functionally equivalent to the Transact-SQL CHECK IDENT statement. An error will be thrown if this method is called on a table with no Identifier columns.

The following code example shows how to check and display the identity value of a table.


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

Table tb = new Table(db, "Test Table");
Column col1 = new Column(tb, "TableIdentifier", DataType.Int);
col1.Identity = true;

foreach (String s in tb.CheckIdentityValue())


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

$tb = new-object Microsoft.SqlServer.Management.Smo.Table($db, "Test Table")
$col1 = new-object Microsoft.SqlServer.Management.Smo.Column($tb, "TableIdentifier", [Microsoft.SqlServer.Management.Smo.DataType]::Int)
$col1.Identity = $TRUE

Write-Host $tb.CheckIdentityValue()
Return to top