Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 将现有列转换为第二个自动增量列_Sql Server_Auto Increment_Identity - Fatal编程技术网

Sql server 将现有列转换为第二个自动增量列

Sql server 将现有列转换为第二个自动增量列,sql-server,auto-increment,identity,Sql Server,Auto Increment,Identity,在Sql Server中,我有一个StudentMaster表,其中有一个IDPrimary列和另一个StudentRollNoNot主列。我需要将StudentRollNo转换为另一个标识列。。我试过这个: ALTER TABLE studentMaster alter column StudentRollNo AS ID + 0 但这不起作用,因为“AS”和“+”在此查询中是不可接受的。Sql Server中还有其他选项吗 CREATE SEQUENCE seq START WITH wa

在Sql Server中,我有一个StudentMaster表,其中有一个IDPrimary列和另一个StudentRollNoNot主列。我需要将StudentRollNo转换为另一个标识列。。我试过这个:

ALTER TABLE studentMaster alter column StudentRollNo AS ID + 0
但这不起作用,因为“AS”和“+”在此查询中是不可接受的。Sql Server中还有其他选项吗

CREATE SEQUENCE seq START WITH watever_number INCREMENT BY 1;

ALTER TABLE studentMaster ADD CONSTRAINT constraint_name 
      DEFAULT NEXT VALUE FOR seq FOR StudentRollNo 
用列中可以在数据库表中使用的最高值替换watever_number

alter table TableName add ComputedColumnName as Id -- Identity column name

一个表中不能有2个标识键,我认为您需要一个唯一的索引altertable studentMaster ADD CONSTRAINT\u name unique StudentRollNo;StudentRollNo不是Primary或者您想要序列这是新列的,我想要现有列的解决方案您可以指导我如何将列修改为序列列吗