Click here to Skip to main content
13,051,413 members (45,417 online)
Rate this:
Please Sign up or sign in to vote.
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 24-Nov-12 9:45am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

declare @userID int
set @userID = Scope_Identity()
gjmkdyttyhujk 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 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100