473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

To make an existing column become an identity column

Hi
(SQL Server 2000)

I have an existing table (t) with a column that is NOT an identity column
(t.ID), but it has manually inserted "row numbers". I want to make this
column become an identity column. This column is a key field to other
tables, so I want to keep the row numbers that are allready inserted.

From the Query Analyzer, how do I do this?

Thanks in advance!

Regards,
Gunnar Vøyenli
EDB-konsulent as
NORWAY
Jul 20 '05 #1
3 19049
Try this.

Copy the table by using Export Data. Then using the copied table set your
column to identity and see if any of the numbers change.

Dave
"Gunnar Vøyenli" <gv@edbkonsulent.no> wrote in message
news:3f********@news.broadpark.no...
Hi
(SQL Server 2000)

I have an existing table (t) with a column that is NOT an identity column
(t.ID), but it has manually inserted "row numbers". I want to make this
column become an identity column. This column is a key field to other
tables, so I want to keep the row numbers that are allready inserted.

From the Query Analyzer, how do I do this?

Thanks in advance!

Regards,
Gunnar Vøyenli
EDB-konsulent as
NORWAY

Jul 20 '05 #2
CJ
Check SET IDENTITY_INSERT in Books Online(BOL). It will allow you to insert
explicit values into an identity field.
CJ
"Gunnar Vøyenli" <gv@edbkonsulent.no> wrote in message
news:3f********@news.broadpark.no...
Hi
(SQL Server 2000)

I have an existing table (t) with a column that is NOT an identity column
(t.ID), but it has manually inserted "row numbers". I want to make this
column become an identity column. This column is a key field to other
tables, so I want to keep the row numbers that are allready inserted.

From the Query Analyzer, how do I do this?

Thanks in advance!

Regards,
Gunnar Vøyenli
EDB-konsulent as
NORWAY

Jul 20 '05 #3
Gunnar Vøyenli (gv@edbkonsulent.no) writes:
I have an existing table (t) with a column that is NOT an identity column
(t.ID), but it has manually inserted "row numbers". I want to make this
column become an identity column. This column is a key field to other
tables, so I want to keep the row numbers that are allready inserted.

From the Query Analyzer, how do I do this?


There is no convenient ALTER TABLE command for this. (Except in SQL
Server CE!). So you need to:

1) Rename the existing table and any constraints it may have.
2) Run a CREATE TABLE statement with the new definition of the column,
including constraints for the table.
3) Isssue SET IDENTITY_INSERT ON for the table to permit inserting of
explicit values in the IDENTITY column.
4) INSERT newtbl (...) SELECT ... FROM oldtbl.
5) Move referencing foreign keys to refer to the new table.
6) Restore triggers and indexes on the new table.
7) drop the old table.

From the Enterprise Manager you can carry out this by point-and-click.
However, what EM performs behind the scenes is something like the above.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jennifer | last post by:
I've got a table with 36+ million rows. I've been asked to modify the table and add in an identity column. The code I used caused SQL to lock up and it maxed out the log files. :) The code I...
7
by: Yannick Turgeon | last post by:
Hello all, I'm using SS2K on W2k. I'v got a table say, humm, "Orders" with two fields in the PK: OrderDate and CustomerID. I would like to add an "ID" column which would be auto-increment...
1
by: ibm_97 | last post by:
DB2 8.2 on AIX Hi, I'd like to change a column's name in a table which is part of replication. This column is identity column (generated always). 1. Since DB2 will drop and recreate the...
2
by: WhiteEagl | last post by:
Hello, I would need some help with this identity column problem in SQLServer. I have a database with two tables. The Parent table has an Identity column. Parent (ParentID IDENTITY, Name)...
1
by: smauldin | last post by:
Creating a table with an identity column works fine create table test(a integer, id integer generated always as identity ) When I attempt to add an identity column it fails. create table...
5
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as...
7
ak1dnar
by: ak1dnar | last post by:
Hi this is my first visit to the MSSQL forum with a question. Let me explain the scenario, I have a table say clients table with the structure like id,foo,etc.. and lots of records on it. But...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
2
by: kostasgio | last post by:
Hello, this is my first post here, i hope i'll find this forum usefull. Although i did a search about my question, i didnt find what i need , because the question isnt exactly what it sounds. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.