Question:
unique key question, sql server 2005
2008-08-07 18:54:35 UTC
How do you add a unique integer key to an existing table full of data? It currently has no key, i want it to auto generate a integer key for existing rows and then auto generate key for future rows? Any code , example, urls would be nice. thanks!
Three answers:
jmorge
2008-08-07 19:22:01 UTC
use the "identity" option when creating your new column. this is like an "auto fill" field that sql will assign an integer to each time a record is added to the table. google "sql identity" and you'll find plenty of websites describing it's use in detail
2016-10-21 09:10:28 UTC
I have performed this beforehand (many situations). Your steps are proper. about classified ads area, you do not really ought to attempt this, until eventually you pick to apply homestead windows authentication instead sq. authentication. you truly favor sq. server administration studio. this provide you with the front-end to have interplay with backend. for sure, you should use odbc on your seen uncomplicated, etc software to have interplay with ms sq. educate. yet i trust it a lot extra positive to apply administration studio & configuration concepts are also easy utilizing this. I gained't recommend utilizing ms sq. educate , try finished version instead. educate ed. has a lot of barriers.
Serge M
2008-08-08 14:56:36 UTC
alter table your_table

add id_key int identity


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...