SQL查询表上的身份键
我在SQL Server 2008中有一张表。它有empId,它是int类型。现在还不是身份。我想编写查询(以便我可以维护数据库中的更改记录)以使该列成为标识列。该表目前没有数据。
I have the table in SQL Server 2008. It has empId, which is the int of type. It is not identity for now. I want to write the query (so that I can maintain the record of changes in DB) to make this columns as identity column. This table have no data currently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是可以做到的,但并不容易。根据这个如果您通过 SSMS 执行此操作,然后生成一个脚本,该脚本基本上:
example1,说 Tmp_Example1 与
身份栏。
刚刚创建。第3步:插入全部
从 example1 到 Tmp_Example1 的值
Tmp_Example..
删除我们原来的表???)
提交事务
如果正如您所说,该表中没有任何数据,那么您最好通过 SSMS 执行此操作(我链接到的文章中提供了步骤)。您想使用 SQL 执行此操作有什么原因吗?
更新
我正在阅读一篇文章用户之前发布并发现这似乎比我上面的方法容易得多:
但同样,通过 SSMS 执行此操作可能更有意义。不过很高兴知道...
It can be done but not easily. According to this article if you do this through SSMS and then generate a script that basically:
example1, say Tmp_Example1 with
Identity Column.
just created.Step 3: Insert all
values from example1 to Tmp_Example1
Tmp_Example..
dropping our original table???)
Commit Transaction
If this table doesn't have any data in it as you say, then you are probably better off just doing this through SSMS (steps are provided in the article i link to). Is there a reason you want to do this using SQL?
UPDATE
I was reading an article that another user posted up earlier and found this which seems much easier than my above method:
But again, it probably makes more sense to do this through SSMS. Good to know though...
您没有数据,因此将表编写为删除并重新创建。将字段更改为 Employeeid int Identity(1,1) not null。然后重新创建表。没有大惊小怪,没有混乱。
You have no data, so script the table as drop and recreate. The change the field to Employeeid int identity(1,1) not null. Then recreate the table. No fuss no muss.