Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add uniqueidentifier field to existing table 1

Status
Not open for further replies.

Lost500

IS-IT--Management
Mar 10, 2009
110
US
Hi all!

I need an unique id field that automatically adds an id number to every record that gets added.

I have a SQL Database on SQL server 2005.

I think the solution is to add uniqueidentifier fields to the tables in a database. all the tables already have data in them I don't know if that matters.

Also, what settings in the uniqueidentifier field do i have to set inorder for the id num to be automatically populated.

Thanks in advance!!!




 
In order for them to automatically populate put NewID() in the default value for the column.
 
You could create a new table with an identity, copy the old table into it, drop the old table, and then rename it.

Code:
create table #TableTwo(PK Int Identity, column1 varchar(5),column2 Varchar(5))

Insert into #TableTwo
select column1,column1 from #TableOne 

drop table #tableone

Then rename it from SQL Server Management Studio or via SP-Rename.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top