This is a discussion on Re: Generating custom keys within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, We had a project where we where maintaining a table for primary to generate and use that value ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, We had a project where we where maintaining a table for primary to generate and use that value in other table. From your eaxplanation i little unclear about what exactly you are trying to do. Can you give some breif overview of scenarion. Thanks , Amit |
| ||||
| They generate their keys by creating a key table for each data table. The key table contains one row which stores the next value to be inserted into the data table. (Actually they maintain 3 integers which get concatonated together to form a Decimal(16), but the principle is the same). So when ever they want to generate a new key, the select the values from the key table, and then update the value in the table. What I want to be able to do is to somehow be able to insert values from a select statement into a table (somehow generating a new key) without using a cursor. I'm not sure it's going to be possible, but I just trying to see if someone has thought of a way to do this. The only way that I think it could even be possible is to load the values I want to insert into a temp table with an identity field. Get the number of records in that table, and instead of incrementing the key table by 1, increment it my the count of the temp table. Then create a function that will generate the key value from the identity field and the intitial value of the key table. I think this would work, but I don't know if performance wise it would be any better than a cursor. Any ideas or thoughts? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |