June 17, 2009 at 12:10 pm
Hello all.
So I can go into the design mode of a table and ctrl + select columns to add them to a primary key however, on extremely large tables this times out. After searching online for over an hour, I can only find code to apply this on a create table statement.
So, other than recreating the table and inserting the data into it, is there a way with T-SQL to apply a multiple column Primary key on a table?
Link to my blog http://notyelf.com/
June 17, 2009 at 12:48 pm
You can run the following:
alter table test add constraint PK_test primary key (fld1, fld2)
The fields you use cannot be nullable, so you may have to use:
alter table test alter column fld1 int not null
Randy
June 17, 2009 at 12:54 pm
Randy has the commands right, but you'll have to drop the existing primary key first.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
June 17, 2009 at 12:59 pm
Yeah, thanks G2. Also, love the quote!
Randy
June 18, 2009 at 7:32 am
Yeah. Don't remember where I got it from, but thought it was worth hanging on to. (The quote)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply