次の方法で共有


Table.CheckIdentityValue メソッド

参照先テーブルのすべての ID 列について整合性を検証します。

名前空間:  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
現在の ID 値と現在の列の値を含む StringCollection システム オブジェクト値。

説明

このメソッドは、機能的には Transact-SQL の CHECK IDENT ステートメントと同等です。 識別子列のないテーブルに対してこのメソッドを呼び出すと、エラーがスローされます。

使用例

次のコード例では、テーブルの ID 値をチェックし、表示する方法を示します。

C#

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;
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("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
$tb.Columns.Add($col1)

Write-Host $tb.CheckIdentityValue()

関連項目

参照

Table クラス

Microsoft.SqlServer.Management.Smo 名前空間

その他の技術情報

テーブル

CREATE TABLE (Transact-SQL)