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 August 4th, 2003, 09:45 AM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generate unique ID when populating a table

I need to populate TABLE_D in database DB1 from TABLE_S in database DB2. TABLE_S contains an ID VARCHAR and I want to populate TABLE_D with an ID INTEGER. Of course, I need to keep the relation between TABLE_S.ID and TABLE_D.ID.
I don't know how to create proc in sql server but I guess that's the only way to do it.

Thanks in advance for any input.
 
Old August 4th, 2003, 06:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you want to convert the varchar to an integer, or do you want to generate a new identity? Do you want the resulting column of be of datatype Identity?

regards
David Cameron
 
Old August 5th, 2003, 03:38 AM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your answers. I think I figured out a solution:
-----------
CREATE TABLE LU_CLIENT_BU(
CLIENT_BU_ID INT IDENTITY(0,1) PRIMARY KEY,
CLIENT_BU_DESC_1 VARCHAR(80),
CLIENT_BU_DESC_2 VARCHAR(80),
CLIENT_BU_DESC_3 VARCHAR(80)
);

INSERT INTO LU_CLIENT_BU
SELECT DISTINCT TARGETBU, CBU, CBU1, CBU2
FROM CLIENT;
-----------
The IDENTITY(0,1) allows to define an automatic increment from 0 to x (+1 each time a row is inserted in the table). So I basically define the new PK CLIEN_BU_ID as INT and then I can populate my new table fromt the old one. A new unique ID is generated for each row inserted.

I don't use the CLIENT table afterward.
Cheers






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Generate Unique values for IDs mphare XSLT 7 November 6th, 2008 12:20 PM
generate unique id capri SQL Server 2000 1 April 6th, 2008 10:18 AM
Create Unique Id langer123 Classic ASP Basics 0 April 6th, 2005 01:27 PM
Creating a Unique ID for each row maxworlund SQL Server DTS 1 March 8th, 2005 09:33 PM
Getting Unique ID from Database Nicky_uk Classic ASP Databases 9 January 26th, 2005 04:45 PM





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