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.
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:
- Customer/Product/Supplier (these can all be inserted into in any order).
- Order - This can only come after the row is in the customers table as it requires a valid customer
- 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.