如何从表中删除标识列
我创建了一个表,其中 employee id
作为身份列。现在,我想删除标识并将数据类型替换为 bigint。我使用的是 Sql 精简版。如何实现这一目标?
I have created a table with employee id
as identity column. Now, I want to remove identity and replace datatype as bigint. I am using Sql Compact edition. How to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信您可以使用 TSQL 从列中删除 IDENTITY 属性。
相反:
您可以在表的设计视图中的 SSMS 中执行此操作。我相信它在幕后做了类似上面的事情。
更新:
需要确认的是,在 SSMS 2K8 中,当您尝试从列中删除 IDENTITY 属性然后保存它时,它实际上会重新创建表(您可以通过在 SQL Profiler 中监视来查看它到底做了什么)。为了在 SSMS 中执行此操作,您需要确保在工具 -> 中关闭“防止保存需要重新创建表的更改”选项。选项->设计师->表和数据库设计器。我认为它默认为“开”,当您尝试以其他方式执行此操作时,这会导致错误消息。
I don't believe you can, using TSQL, remove the IDENTITY property from a column.
Instead:
You can do it in SSMS in the Design view for the table. I believe behind the scenes it does something like above.
Update:
To confirm, in SSMS 2K8 when you try to remove the IDENTITY property from a column and then save it, it will actually recreate the table (you can see what it does exactly by monitoring in SQL Profiler). In order to do it in SSMS, you need to ensure you have the "Prevent saving changes that require table re-creation" option turned OFF in Tools-> Options -> Designers -> Table and Database Designers. I think it defaults to ON, which would result in an error message when you try to do it otherwise.
在“真正的”SQL Server 中,您必须执行这些步骤 - 不确定 SQL Server CE 是否允许这样做,但请尝试一下!我假设您可能对该列也有 PRIMARY KEY 约束 - 对吗?如果没有,则无需执行第一步和最后一步。我假设您想再次在列上显示 IDENTITY,对吧?
In "real" SQL Server, you'd have to do these steps - not sure if SQL Server CE allows the same, but give it a try! I'm assuming you probably have your PRIMARY KEY constraint on that column, too - right? If not, you don't need to do the first and last step. And I'm assuming you want to have the IDENTITY on the column again, right?