sql server - How to perform Insert when more tables are related -


After

I have created table 3 in the database as tbProducts, tbLineOfAuthority, tbProductLineOfAuthority

tbProducts after feilds

  • ProductDescription
  • tbLineOfAuthority occurs after feilds

  • LineOfAuthorityId (P) Identity (P)
  • ProductId (FK)
  • LineOfAuthority (FK)
  • Now include tbLineOfAuthority

    • 1 - Electronic insurance
    • 2 - Number
    • 3 - Creativity
    • 4 - Debit

    In the front I have the form with the following types

  • Products
  • Product description (Multilingual textbox)
  • Line of authorization (checkboxes for all lines of authorization)
  • If user

  • "We provide good mobile phones ..." as a product description
  • "Caution" as the line of authorization (sub The user will check the "Cadmium" check box)
  • Now my question is based on the requirement above to insert operation in MS SQL Server and if more than two tables related to the foreign key Are there.

    I have written the stored procedure as

    Insert tbProduct (product name, ProductDescription) value (@ProductName, @ProductDescription)

    I am confused about how I will write a stored procedure which automatically updates tbProductLineOfAuthority (productId and LineOfAuthorityId)

    What will happen besides the selection of several lines of authorization from the user's inquiry In the form of boxes, I mean that the user's casuality, credit and Will select Ebit.

    Please help me!

    To cap the cap, you must type tbProducts and tbLineOfAuthority < For the table / table, some 3 parameters will be given below for the table, once you have entered the record, use SCOPE_IDENTITY () to identify the newly created code [Note that both tables PK columns are identity column].

    Create process sp_insert_ops (@ product name, @ productive description, @tbinlineoff authority) starting @tbProduct_ID INT; Enter the TbProduct (Product Name, Product-Category) Price (@ Product Name, Product Details); SELECT @tbProduct_ID = SCOPE_IDENTITY (); Include TbProductLineOfAuthority (Product ID, LineAff Authority) values ​​(@tbProduct_ID, NULL); End

    Comments

    Popular posts from this blog

    apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

    c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

    c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -