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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Removing the Identity column

Author  Topic 

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2007-05-14 : 10:26:22

Hi,

I have a table with an identity column.

I want to swap 2 of the values in my identity column. To do this I have attempted to get rid of the "IDENTITY" from the column but without success.

Can somebody help?

Thanks in advance
Kabir

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 10:28:37
"Swap"?
What are you trying to accomplish?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-14 : 10:30:30
1) SELECT * INTO #TempTable FROM OriginalTable
2) DELETE FROM OriginalTable WHERE ID IN (3, 4)
3) SET IDENTITY_INSERT OriginalTable ON
4) INSERT OriginalTable SELECT 4, ... FROM #TempTable WHERE ID = 3
5) INSERT OriginalTable SELECT 3, ... FROM #TempTable WHERE ID = 4
6) SET IDENTITY_INSERT OriginalTable OFF


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2007-05-14 : 10:31:57

I have the following values in my table:

ColA ColB
------------
1 Text A
2 Text B
3 Text C
4 Text D

I want the 3 to become 4, and the 4 to become 3.

Cheers,
Kabir
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-14 : 10:38:16
Where do you want to show data?
If you use front end application, do numbering there
All you need to do is sort it by colb and number them when displaying

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-15 : 09:29:37
Peso, it seems you updated your reply
Can you highlight that?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-16 : 00:55:05
I changed ID {1,2} to {3,4} to avoid confusion...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -