Sql server 将现有列转换为第二个自动增量列
在Sql Server中,我有一个StudentMaster表,其中有一个IDPrimary列和另一个StudentRollNoNot主列。我需要将StudentRollNo转换为另一个标识列。。我试过这个: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
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或者您想要序列这是新列的,我想要现有列的解决方案您可以指导我如何将列修改为序列列吗