Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2005, 01:55 AM
Registered User
 
Join Date: Feb 2005
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

 
Old July 5th, 2005, 10:51 AM
Friend of Wrox
 
Join Date: Nov 2003
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.

 
Old July 5th, 2005, 05:42 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old July 5th, 2005, 11:25 PM
Friend of Wrox
 
Join Date: Nov 2003
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

 
Old July 6th, 2005, 05:53 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old July 6th, 2005, 08:44 AM
Friend of Wrox
 
Join Date: Nov 2003
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






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 [email protected] Access 2 July 29th, 2003 03:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.