在程式中重新設定 SQL Server 資料表的流水號欄位

在程式中呼叫 DBCC CHECKIDENT 命令來重設 SQL Server 資料表的流水號欄位。
範例:
string cnstr = "server=.;Database=MyDB;uid=sa;pwd=";
using (SqlConnection cn = new SqlConnection(cnstr))
{
    cn.Open();
    SqlCommand cmd = new SqlCommand("DBCC CHECKIDENT('MY_TABLE', RESEED, 0)", cn);
    cmd.ExecuteNonQuery();
}
Copyright © 2012. Huan-Lin 學習筆記 - All Rights Reserved
Powered by Blogger
Template Design by Cool Blogger Tutorials
Published by Templates Doctor