数据库设计中混淆的表中的多个ID [“已解决"] [英] multiple Id in a table confused in database design["Solved"]
问题描述
我正在开发一个应用程序,其中一个表用于存储客户信息,而另一个表用于存储我的产品.产品没有限制,因为会在上面添加任何新产品.
每次添加客户时,我都会通过选择每个产品的复选框来提供从所有产品列表中选择任何产品的选项.在此过程之后,用户将单击提交"按钮.我想存储选择的每个产品的ID并将其与客户ID一起存储到数据库中.但是我在数据库设计中非常困惑.请帮助...
[edit]删除了虚假代码块-OriginalGriff [/edit]
I am making a app in which one table is for storing client information and other is the for products I have. There is no limit of products as any new product will be added on it.
Each time I add a client I give options to select any product from all list of products by selecting checkbox of each product.After all this process user will click submit button. I want to store the Id of each product selected and store it into database with customer Id.But I am very confused in database design.Please Help...
[edit]Spurious code block removed - OriginalGriff[/edit]
推荐答案
听起来您需要三个表,而不是两个表.
客户表:
Sounds like you need to have three tables, not two.
Customer table:
CID, Name, Address, etc.
产品表:
Product table:
PID, Name, Description, Price, Image, etc.
CustomerOrderDetail:
CustomerOrderDetail:
OID, CID, PID, Date, etc.
可能是您想要第四个表来处理来自客户的单个订单:一起交付,一起开具发票,一起付款等等.
在这种情况下,您可以将第三个表替换为两个.
客户订单:
It may be that you want a fourth table to handle individual orders from a customer: Ones that get delivered together, invoiced toghether, paid together, and so forth.
In which case you would replace the third table with two.
CustomerOrder:
COID, CID, Date, status, etc.
CustomerOrderDetail:
CustomerOrderDetail:
CODID, COID, PID, etc.
例如,当您可能每周都有客户下订单时,以后的设置会更正常.
The later setup is more normal when you might have a customer making an order each week, say.
您好,
您可以在数据库中维护2个表,分别是 TblProduct 和 TblClient .
例如:
Hi,
You can maintain 2 tables in your database namely, TblProduct and TblClient.
for ex:
create table TblProduct(
ProductID int primary key not null,
ProductName varchar(50) not null,
ProductDetails varchar(100) not null)
和
and
create table TblClient(
ClientId int primary key not null,
ClientName varchar(50) not null,
ClientDetails varchar(100) not null,
ProductID1 int not null)
稍后,您可以使用查询来检索所需的所有详细信息,并将其显示为最终结果.
Later you can use a query to retrieve what all details you need and display it as your end result.
select * from TblProduct
将会产生:
will yield:
ProductID ProductName ProductDetails
1 BMW vehicles
2 Lenovo PC
3 HP PC
4 Kingston Peripherals
select * from TblClient
将会产生:
will yield:
ClientId ClientName ClientDetails ProductID1
100 YY BeachSide 1
101 XX RiverSide 2
102 ZZ CountrySide 5
103 AA No Details 4
105 BB TownHall 6
然后,您可以使用类似以下的查询:
Then you might use a query like:
select TblClient.* from TblClient join TblProduct on TblProduct.ProductID=TblClient.ProductID1
基于以上条目的答案将产生:
The answer based upon the above entries will yield:
ClientId ClientName ClientDetails ProductID1
100 YY BeachSide 1
101 XX RiverSide 2
103 AA No Details 4
它提供了购买产品清单中所含产品的客户的详细信息.如果需要,可以将其存储在单独的表中.
希望对您有帮助
It gives the details of the clients who have purchased the product which is present in the product list.You can store it in a separate table if you want.
Hope it helps
这篇关于数据库设计中混淆的表中的多个ID [“已解决"]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!