March 2, 2009 at 11:37 am
I have a table in which I set the primary key data field as unique identifier.I am using Vs 2008 for the front end
But I need to change the Primary key field into integer type.But when i am trying to do that i am getting some error message.So can i duplicate this table in such a way that the primary key field is changed into integer data type.Please let me know.
March 2, 2009 at 11:41 am
You could fix the table by creating a temporary table, inserting the data into it, then dropping the real table and re-creating it with the new PK, and then inserting from the temp table.
If you do that, make sure that you wrap the whole thing in a transaction, so if anything goes wrong, you can roll back the whole thing.
- 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
March 2, 2009 at 11:42 am
I'd go with Gus' advice.
create new table
begin tran
select into from old table (minus GUID)
drop old table
rename new table
commit
March 2, 2009 at 11:46 am
Thanks alot Guys....
March 2, 2009 at 11:53 am
As Gus beat me to the punch, I'd just like to add to be cognizant of any FK relationships you have defined on other tables... want to make sure you take those into consideration before making this type of change to the db, don't want a whole bunch of orphaned records and such.
-Luke.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply