Insert data to tables [closed]

2019-09-24 01:53发布

I want to insert data and realize order operation from user input data. I created this tables:

Order
|OrderID - PK|CustomerID - FK|OrderDate|

OrderDetails
|OrderID - PK,FK|ProductID - PK,FK|Quantity|

Customer
|CustomerID - PK|FirstName|LastName|Address|

Product
|ProductID - PK| |SuplierID - FK| |Quantity|

Supplier
|SupplierID - PK|Name|

I want to use stored procedure to insert data, but I've problem with construct t-sql.

1条回答
在下西门庆
2楼-- · 2019-09-24 02:35

if i understand the question correctly, you want to know which order to insert data into tables to ensure no violations, is that correct?

From your post it looks like you insert in this order:

  1. Customer/Product/Supplier (these can all be inserted into in any order).
  2. Order - This can only come after the row is in the customers table as it requires a valid customer
  3. Order Details - this requires an entry in the order table and product table first.

Quantity column would be on the OrderDetail table, as you can have more than one of each line item.

查看更多
登录 后发表回答