Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,
I am writing a program and i have 2 table with a column named User id that this column is primary key in both of tables.and user id in one of tables is fill if other column is filled and it have a seed and an increment.when i write a query for adding data in that table i want to user id to be add to other table by the same value that i have in first table
what i must do?
Posted

1 solution

You have to insert first in the user table and after that ask the newest identity.
Store that value in a variable and use it in your second insert.

SQL
declare @userID int

set @userID = Scope_Identity()
 
Share this answer
 
Comments
_Starbug_ 24-Nov-12 17:11pm    
thank you.but i mean I can not insert a value for my first user id and when i want to add a row to my first table i enter data for all of my column's not in user id but it's value increase 2 number by seed 1000 and I want to add this new value of user id for other table that it have.is this work can done with sql automatically?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900