I have one existing table called 'x' contains 'n' columns and trying to add one more column called ID which should have value with 1 to 128 (because i have 128 rows) in table.how can i do this using sql.
Asked
Active
Viewed 158 times
-1
-
1If you add additional rows, should it continue incrementing? (I assume so) See [Insert auto increment primary key into existing table](http://stackoverflow.com/questions/9070764/insert-auto-increment-primary-key-to-existing-mysql-database/9070808#9070808) – Michael Berkowski Feb 11 '15 at 05:13
-
thanks for hint Michael,since i am using SQL server IDENTITY do work of AUTO_INCREMENT hence fallowing command works fine . ALTER TABLE tb1 ADD id INT PRIMARY KEY IDENTITY – Veeresh Honnaraddi Feb 11 '15 at 05:34
-
Retagging from mysqli to sql server then. – Michael Berkowski Feb 11 '15 at 05:41
1 Answers
1
You can ALTER query with IDENTITY(1,1) for the new column.
ALTER TABLE x ADD ID INT IDENTITY(1,1) PRIMARY KEY

Veera
- 3,412
- 2
- 14
- 27