Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sequence to update key

Author  Topic 

nintendo
Starting Member

2 Posts

Posted - 2009-01-22 : 19:25:36
i'm new so plz take it easy on me :)

table1 has c1 and c2 ......lets say c=column
table2 has c1 and c2

table 2 is empty and table 1 has over 200 values in each column.
i need to write a "sequence" to increment c1 in table2 (effectively the key) everytime a new value is put into c2 of table2.

now for single value inserts i could have used a simple trigger. but ALL the data from table1 c1 needs to be copied into table2 c2.
how do i make a complex sequence or batch trigger to handle this?

nintendo
Starting Member

2 Posts

Posted - 2009-01-22 : 19:44:29
guys i'd really appreciate any help. even an external help link or pseudo code would help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-22 : 23:14:48
just make column c1 in table2 identity column with a seed and increment. then each time insertion happens, the column value will automatically increment based on increment value set.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-22 : 23:40:10
if u not create table2 then u can use this (with identity column)
try like this
select identity(int,1,1)as c1 ,* into table2 from table1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-23 : 00:51:48
quote:
Originally posted by bklr

if u not create table2 then u can use this (with identity column)
try like this
select identity(int,1,1)as c1 ,* into table2 from table1



only problem is that you cant guarantee that identity value created will be according to order of retrieval by select and hence this wont always work correctly

http://support.microsoft.com/kb/273586
Go to Top of Page
   

- Advertisement -