CheckIdentityValue 方法
验证被引用表中所有标识列的完整性。
命名空间: Microsoft.SqlServer.Management.Smo
程序集: Microsoft.SqlServer.Smo(在 Microsoft.SqlServer.Smo.dll 中)
语法
声明
Public Function CheckIdentityValue As StringCollection
用法
Dim instance As Table
Dim returnValue As StringCollection
returnValue = instance.CheckIdentityValue()
public StringCollection CheckIdentityValue()
public:
StringCollection^ CheckIdentityValue()
member CheckIdentityValue : unit -> StringCollection
public function CheckIdentityValue() : StringCollection
返回值
类型:System.Collections.Specialized. . :: . .StringCollection
一个 StringCollection 系统对象值,该值包含当前标识值和当前列值。
注释
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.
C#
Server srv = new Server("(local)");
Database db = srv.Databases["AdventureWorks2008R2"];
Table tb = new Table(db, "Test Table");
Column col1 = new Column(tb, "TableIdentifier", DataType.Int);
col1.Identity = true;
tb.Columns.Add(col1);
foreach (String s in tb.CheckIdentityValue())
{
Console.WriteLine(s);
}
Powershell
$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $srv.Databases.Item("AdventureWorks2008R2")
$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
$tb.Columns.Add($col1)
Write-Host $tb.CheckIdentityValue()