views:

48

answers:

2

Ok, this is probably really simple, but I just can't figure it out. I have a primary key in a table that goes from 1-5,000. I need to manually update that id (for other table update purposes) so that it says 5,000-10,000. Can't I manually update this column? Please help!!! Thank you

+3  A: 
SET IDENTITY_INSERT tableName ON

UPDATE tableName
SET columnName = columnName + 5000

SET IDENTITY_INSERT tableName OFF
David B
Sorry, maybe I should clarify. I need it to start with 5,000-10,000, in place of 1-5,000
Wesley
SET columnName = columnName + 5001then SET columnName = columnName -1 (otherwise you will get error about duplicate primary key). So you need to execute 2 UPDATE statements.
a1ex07
thanks, that what I needed!!
Wesley
A: 

If you go in cpanel (if you are using it) and browse and edit, in the primary key field leave it as auto incement but change the first record to 5,000 it might autoupdate the rest?

not so simple and maybe not relevant, but can't you run a script in php or similar to loop through all records and apply set primarykeyvalue to primarykeyvalue+4,999 ?

princessmarisa