SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Removing the Identity column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 05/14/2007 :  10:26:22  Show Profile  Reply with Quote

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

Sweden
30276 Posts

Posted - 05/14/2007 :  10:28:37  Show Profile  Visit SwePeso's Homepage  Reply with Quote
"Swap"?
What are you trying to accomplish?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30276 Posts

Posted - 05/14/2007 :  10:30:30  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

Edited by - SwePeso on 05/14/2007 11:36:14
Go to Top of Page

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 05/14/2007 :  10:31:57  Show Profile  Reply with Quote

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

India
22765 Posts

Posted - 05/14/2007 :  10:38:16  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
22765 Posts

Posted - 05/15/2007 :  09:29:37  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

Sweden
30276 Posts

Posted - 05/16/2007 :  00:55:05  Show Profile  Visit SwePeso's Homepage  Reply with Quote
I changed ID {1,2} to {3,4} to avoid confusion...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000