Click here to Skip to main content
11,576,993 members (52,216 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server-2008
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
good
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()
  Permalink  
Comments
gjmkdyttyhujk at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 251
1 DamithSL 155
2 Abhinav S 130
3 OriginalGriff 105
4 Afzaal Ahmad Zeeshan 85
0 OriginalGriff 715
1 Sergey Alexandrovich Kryukov 631
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 24 Nov 2012
Copyright © CodeProject, 1999-2015
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