SQL Server 2008中的数据库表 [英] Database table in SQL Server 2008
问题描述
我正在做TY项目,其中有一个客户表和一个存储纸张名称的纸质表。我想将客户订购的纸质订单存储在订单表中。
如何操作?请帮忙。
I am doing TY project where there is a customer table and a paper table which store the names of the paper. I would like to store the paper order made by the customer in the order table.
How to do it? Please help out.
推荐答案
如果客户只能有一张纸,那么这很简单 - 您只需在Customer表中创建一个字段即可是与Paper表行的ID相同的数据类型,并将纸张的ID放入customer表。
所以,如果你有一个Paper表
If the customer can only have one paper, then that is quite easy - all you have to do is create a field in the Customer table which is athe same datatype as the ID for the Paper table rows, and put the ID for teh paper into the customer table.
So, if you have a Paper table
ID (int) PaperName (varchar(200))
1 Times
2 Mirror
3 Globe
和一张Customer表
And a Customer table
ID (int) CustomerName (varchar(200)) PaperID (int)
1 Joe 2
2 Mike 3
3 Dave 2
然后这表明Joe和Dave都拿了Mirror论文,而Mike拿了Globe。 (您也可以将PaperID设置为外键,SQL将强制执行该ID匹配)
如果您希望客户能够同时使用Mirror和全球,然后你需要设置第三个表,而不是具有CustomerID和PaperID:
Then that would indicate that Joe and Dave both take the "Mirror" paper, while Mike takes the "Globe". (You can also set the PaperID as a Foreign Key, and SQL will enforce that ID match)
If you want a customer to be able to take both the Mirror and the Globe, then you need to set up a third table instead which has the CustomerID and the PaperID:
ID (int) PaperName (varchar(200))
1 Times
2 Mirror
3 Globe
ID (int) CustomerName (varchar(200))
1 Joe
2 Mike
3 Dave
ID (int) CustID (int) PaperID (int)
1 1 2
2 2 3
3 3 2
4 3 3
这篇关于SQL Server 2008中的数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!