Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 5th, 2005, 01:55 AM
Registered User
 
Join Date: Feb 2005
Location: Faridabad, Haryana, India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Alter a column as identity for table

Hi All,
URGENT requirement !!!

In my table, i wants to alter the column namde 'ID' as identity column for that table. 29 rows are also their with unique numbers and this a int type column. Please tell me how to this from query-analyzer (not from Entr.Mngr.)

Thanks to all my friends,

Hans Raj

Reply With Quote
  #2 (permalink)  
Old July 5th, 2005, 10:51 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You cannot use alter to change the column to identity, you will have to use EM.

Reply With Quote
  #3 (permalink)  
Old July 5th, 2005, 05:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by jbenson001
 You cannot use alter to change the column to identity, you will have to use EM.
Yup ... and if you inspect what EM does when you do this by looking at the generated script, you'll see that it "modifies" a column to be an identity by creating a temporary table with the new column definition as an identity column, turning IDENTITY_INSERT on, copying the contents of the old table into the new one, dropping the old table then renaming the temporary to the old name. It'll also deal with any indexes or primary key constraints by dropping and re-adding them.

If you absolutely must do this via QA, use EM, make your changes, generate the script, save the script, discard the design changes, then later execute the script you saved.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply With Quote
  #4 (permalink)  
Old July 5th, 2005, 11:25 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Jeff.. I was wondering how EM did this. How do you see all the steps it takes to do as you said? Just curious..

Thanks... Jim

Reply With Quote
  #5 (permalink)  
Old July 6th, 2005, 05:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by jbenson001
 Jeff.. I was wondering how EM did this. How do you see all the steps it takes to do as you said? Just curious..

Thanks... Jim
In EM, make your design changes to the table. Notice that the script icon in the toolbar (3rd from the left in table design mode) enables when you make any design change to a table. If you click it, you'll see the generated script that EM will use to make your changes. You can save this script to a file or copy it to the clipboard.

Very handy sometimes...


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply With Quote
  #6 (permalink)  
Old July 6th, 2005, 08:44 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Thanks Jeff,

   I never notticed this before. I figured thhere was a way. That is really cool, and can come in handy.

Thanks again....

Jim

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i alter table (primary key + identity ) keyvanjan SQL Server 2000 1 July 12th, 2007 06:49 AM
Alter Column SQLScott SQL Server 2005 5 January 5th, 2007 11:53 AM
getting identity column from the table g_vamsi_krish SQL Server 2000 1 March 15th, 2006 05:05 PM
Alter Default on a Column Gert SQL Server 2000 4 November 28th, 2003 08:58 AM
Alter Table - Add Column liz@trinityholdings.co.za Access 2 July 29th, 2003 03:06 AM



All times are GMT -4. The time now is 05:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.