向表中插入数据 [英] Insert data to tables
本文介绍了向表中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从用户输入的数据中插入数据并实现订单操作.我创建了这个表:
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|
我想使用存储过程插入数据,但我在构建 t-sql 时遇到问题.
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:
- 客户/产品/供应商(这些都可以按任何顺序插入).
- 订单 - 这只能在客户表中的行之后出现,因为它需要一个有效的客户
- 订单详细信息 - 这需要先在订单表和产品表中输入.
Quantity 列将位于 OrderDetail 表中,因为您可以拥有多个行项目.
Quantity column would be on the OrderDetail table, as you can have more than one of each line item.
这篇关于向表中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文