Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JSG_Martin
Starting Member
6 Posts |
Posted - 2007-11-21 : 10:58:47
|
| Hi,I currently have a table which has around 60000 records, within the table there is a field which is acting as the Primary but the numbers are not in consecutive order any more (due to deletion), and i need a SQL Script that will start at the beginning of the records and UPDATE (STK_LOCATION) and SET the field (LOC_PRIMARY) to 1 on the first record and then go through the rest of the table setting the same field to +1 of the record before it.Any help and advice will be very gratefulThanks in advance |
|
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2007-11-21 : 11:03:44
|
| This will break your referential integrity. Any other table(s) that link to it will no longer link properly. |
 |
|
|
JSG_Martin
Starting Member
6 Posts |
Posted - 2007-11-21 : 11:22:03
|
| Don't worry about that, i have worked out the two table which require the numbers to be the same and once one table has been updated i will do a match up after. |
 |
|
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2007-11-21 : 11:29:16
|
| The best way I can think of to tell you to do it is to create a similar table and repopulate it ordered by your current PK so the rows get inserted into the new table in the correct order and let the new table repopulate the PK for you when the insert occurs. Other than that, you will probably have to set up a loop to do it. |
 |
|
|
|
|
|