Detai Master l Table

  • Hi All

    I have two tables=

    Master table

    id_master, int, Autoincremental

    detail_table

    id_master

    id_detail,int Autoincremental

     

    My question is, in the detail table, how create a table that the id_detail start in 1, when a id_master is new?

     

    Example

    Master_table

    id_master

    1

    2

    3

     

    detail_table

    id_master         id_detail

    1                          1

    1                           2

    1                          3

    2                           1

    2                             2

    3                           1

    How do I do it every time a new id is added in the "master" start of 1 in the "detail"?

  • Do you want a stored proc to do this?

    Are all of the detail rows created at the same time as the parent?

    What is the PK of the detail table?


  • PLEASE don't duplicate posts.  All does is split up the answers others make.

    Please, no more answers on this thread folks.  Instead, post them on the following thread.

    https://www.sqlservercentral.com/forums/topic/master-and-detail-table

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply