Click here to Skip to main content
15,884,758 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make ID2 column to identity column what do I do..
SQL
create table Example1
(
	ID1 INT PRIMARY KEY, 
	ID2 INT,
)
Posted
Updated 14-Dec-14 22:18pm
v2

Do this

create table Example1
(
ID1 INT PRIMARY KEY,
ID2 INT IDENTITY (1, 1),
)


and refer

how-to-alter-column-to-identity[^]

for more details
 
Share this answer
 
Comments
Tomas Takac 15-Dec-14 4:28am    
+5 for the alter
Shweta N Mishra 15-Dec-14 4:40am    
thank you :)
Try Like this,
SQL
create table Example1
(
	ID1 INT PRIMARY KEY, 
	ID2 INT IDENTITY(1,1)
)
 
Share this answer
 
Comments
Tomas Takac 15-Dec-14 4:27am    
+5 for doing what I meant to do ;)
Rajesh waran 15-Dec-14 4:45am    
Thanks Tomas
If the table is already created and you have records in them.
You could try out this link:
http://stackoverflow.com/questions/1049210/adding-an-identity-to-an-existing-column[^]
 
Share this answer
 
Comments
K.Y.S.Phaneendra 15-Dec-14 5:13am    
Got it,
Thank you...
jaket-cp 15-Dec-14 5:14am    
glad to help :)
This is trivial, you should read documentation[^] properly. BTW your tags don't say what database you are using. I assume SQL Server.
SQL
create table Example1
(
	ID1 INT PRIMARY KEY, 
	ID2 INT IDENTITY(1,1),
)
 
Share this answer
 
v2
Comments
Rajesh waran 15-Dec-14 4:23am    
Dude He want to add identity to ID2 not ID1.
Tomas Takac 15-Dec-14 4:25am    
Right, thanks for noticing. I was assuming he wants it on PK automatically.
K.Y.S.Phaneendra 15-Dec-14 4:25am    
I am sorry I use SQL server only but my problem is that if I already created the table and want to make the ID2 as IDENTITY COLUMN
Tomas Takac 15-Dec-14 4:28am    
See solution 2 for details.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900