Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Red face Unanswered: Primery key and foregion key

    Have a good day

    lets assume that i have 2 tables

    First one is customer table and has primery key called cusid

    second one is order table and has foregion key custid

    how i can coonect them , what i mean exactly when insert the record in the customer table i need the foregion key get the same value as primery key in customer table ,,

    appreciate your help

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    if the primary key in the first table is an IDENTITY column, use the SCOPE_IDENTITY function after the first insert

    it's described quite well in da manual
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2010
    Posts
    4
    anybody can provide me with code example

  4. #4
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,418
    Provided Answers: 7
    is the CusID the same data type in the Order table
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  5. #5
    Join Date
    Feb 2010
    Posts
    4
    yes it's the same ..

    Custid in the customer tabel ( Integer , autoincrement and Primery key )

    Custid in order table ( Integer and foregion key )


    i want to make relations btw them by using scope identity to make the vlaue in Ordaer table same as in customer table

    you can find in the attachment my code ..

    hope if you can help me to do it asap

    Regards
    Attached Files Attached Files

  6. #6
    Join Date
    Feb 2010
    Posts
    4
    I did it finally ..

    thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •