Skip to content

Idenity key value(primary key) send to another Table as Foreign key

Aamir Khan

Asked Jun 24, 2012, 10:20 PM EDT2 answers
Share
LinkedInX
Hi friends,
i have one table named Proj_KitDetls in which there is a Column named Id which is Identity key & primary key.and another table named Proj_kitInvDetls in which i m saving the Identity key of Proj_KitDetls as Foreign key,
but i am not able to set the values in Proj_kitInvDetls.
example: in Proj_KitDetls tables values are set in DB like this:

Id,CTNo,Kitname,KitType,BudgetUnits
86,4,CASS30KIT90,Combo Kit,10

Proj_kitInvDetls another table has value like this:
KItd(primarykey),Id(Foreignkey),Invoice_Id,Units
16,8,3,9

the value 86 is not getting set in place of 8 in Table Proj_kitInvDetls.

need help
aamir

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    First insert records into ProjectKit table.
    Use scope_identity() to get the identity value of the ProjectKit table and store into a variable.
    Use the identity variable into projectkit inventory details to insert the record.

    insert into projectkit values (.......)

    declare @id = scope_identiy()

    insert into projectkitinventorydetails (projectuid,...) values (@id,....)

    In your current case, how you're getting the identity column value?
    0
  • 0
    thanks Murali, i got my mistake in the Code, i was not passing the Identity variable value from .aspx Form properly. Regards, Aamir
    0