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!

Distinct Value

Status
Not open for further replies.

JLizOB

Programmer
Dec 5, 2007
45
CA
I have a staging table that will be broken down and inserted into 5 other tables programmatically. I need to create a primary key for each row using the data that will be inserted into that table, columns range from 3 to 50 for the tables. Keepin mind when I pull data for each table I am pulling distinct data. I was wondering if SQL server had any type of hashing function or if anyone knew a good way to do this on SQL Server's side? Thanks!
 
If the data itself has no unique identifier, I'd create an identity field and use it as the primary key in the staging table. Depending on your structure and how unique the records are that will go into the parent table, I might create a field in the parent table to store this identity record (making it easier to match back to the other records to do the other inserts if the data for the parent table is not unique such as if it stores names and you can only tell if the two John Smiths are different from the address which is in the other table).

I would also create a field in the staging table to store the primary key of the parent table you are inserting the records into. That way you have that key available to insert the other data into the child tables.


"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top