0

in Sql Server I have a table StudentMaster in which I have One ID(Primary) column and other "StudentRollNo"(Not Primary) Column . I need to convert StudentRollNo as Another Identity Column .. I Tried this :

ALTER TABLE studentMaster alter column StudentRollNo AS ID + 0

But this is not working 'AS' and '+' are not acceptable in this Query . Is there any other Option in Sql Server ??

Neeraj Verma
  • 2,174
  • 6
  • 30
  • 51

2 Answers2

0
CREATE SEQUENCE seq START WITH watever_number INCREMENT BY 1;

ALTER TABLE studentMaster ADD CONSTRAINT constraint_name 
      DEFAULT NEXT VALUE FOR seq FOR StudentRollNo 

Replace watever_number with the highest value in your column

Mihai
  • 26,325
  • 7
  • 66
  • 81
0

You can use SQL Computed column on your database table

alter table TableName add ComputedColumnName as Id -- Identity column name
Eralper
  • 6,461
  • 2
  • 21
  • 27