如何在Sql Server中为现有列添加标识 [英] How to Add Identity to Existing Column in Sql Server

查看:99
本文介绍了如何在Sql Server中为现有列添加标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

alter column id int not null Identity(1,1)..



它给我一个错误,因为关键字'Identity'附近的语法不正确。

alter column id int not null Identity(1,1)..

Its giving me an error as Incorrect syntax near the keyword 'Identity'.

推荐答案

首先运行这个



first run this

Alter TABLE [dbo].[t_name]
    drop column [id]





然后运行这个



then run this

Alter TABLE [dbo].[t_name]

add  [id] [int] IDENTITY(1,1) NOT NULL


通常,我使用SQL Server Management Studio。我可以简单地打开和关闭IDENTITY。缺少这个,一个解决方案是添加一个新列,然后删除旧列。



Normally, I use the SQL Server Management Studio. I can simply toggle IDENTITY on and off. Lacking this, one solution is to add a new column and then drop your old one.

ALTER TABLE (yourTable) ADD NewColumn INT IDENTITY(1,1)

ALTER TABLE (yourTable) DROP COLUMN OldColumnName










.


参考:添加一个标识到现有列 [ ^ ]


这篇关于如何在Sql Server中为现有列添加标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆