【发布时间】:2014-10-31 23:14:16
【问题描述】:
我试图使用 Microsoft.SqlServer.Smo 从没有依赖关系的表中更改列 IDENTITY,并且之前加载了所有数据(从另一个数据库),但我收到类似这样的错误“修改不允许使用列对象。您必须删除并重新创建具有所需属性的对象“。问题是我试图用 Management Studio 来做这件事,它没有问题。你有什么建议吗?。提前致谢
这是代码:
foreach (Column source in sourcetable.Columns)
{
try
{
if(source.Identity)
{
Column column = copiedtable.Columns[source.Name];
// column.Computed = source.Computed;
// column.ComputedText = source.ComputedText;
column.Identity = source.Identity;
column.IdentityIncrement = source.IdentityIncrement;
column.IdentitySeed = source.IdentitySeed;
column.Alter();
}
}
catch { }
}
【问题讨论】:
-
您无法在现有列中添加或删除
IDENTITY。由于这在 T-SQL 中是不可能的,因此使用 SMO 也是不可能的.....
标签: c# sql-server