Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Can i declare a column as a primary key after creating the table? Can u send me the syntax for that
Posted

1 solution

yes you can..

SQL
Create table testTable (userID int not null, userName varchar(20))
--now if you want to make UserID as primary key, then
alter table testTable add constraint pk_userID primary key (userID)
 
Share this answer
 
v2
Comments
Sandeep Mewara 28-Sep-10 15:27pm    
Well, you should have also added to your answer that this conversion can fail if the values in specified column are not unique.
So, its a Yes & a No.
Om Prakash Pant 29-Sep-10 1:14am    
It is not about column is unique or not. you cannot convert any data to any format. see this link on what you can convert and to which datatypes..

http://msdn.microsoft.com/en-us/library/ms187928.aspx

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