我应该将“quotation_request”作为我的数据库中的表格存储吗?

时间:2022-04-17 04:18:23

I'm working on a very simple DB.

我正在研究一个非常简单的数据库。

Imagine I've table customer and table seller.

想象一下,我是表客户和表卖家。

The customer is able to request a quotation for some products

客户可以请求某些产品的报价

There will be a simple form that allow to customers to select products and submit the quotation.

将有一个简单的表格,允许客户选择产品并提交报价。

Now, should I create table : "Quotation" and store all quotations (with id_quotation..etc)?

现在,我应该创建表:“Quotation”并存储所有引用(使用id_quotation..etc)?

Thank you all

谢谢你们

1 个解决方案

#1


0  

Without knowing all of the business rules that govern the requirements of this database, perhaps the following design will help to answer your question and explain a few concepts in the process.

在不了解管理此数据库要求的所有业务规则的情况下,以下设计可能有助于回答您的问题并解释该过程中的一些概念。

In database terms, an entity is a person, place, or thing about which we want to collect and store data. From your description we can already see two entities: seller and customer. This is important since the entities we identify conceptually become database tables in their own right.

在数据库术语中,实体是我们想要收集和存储数据的人,地点或事物。根据您的描述,我们已经可以看到两个实体:卖家和客户。这很重要,因为我们识别的实体在概念上本身就是数据库表。

The seller table should contain data applicable only to sellers. Thus, the qualities (attributes) about sellers that we want to store become columns in our seller table. Each row (record) in the seller table represents an individual seller. Each individual seller is uniquely identified in the seller table with a unique value stored in it's primary key column, which we can name seller_id.

卖方表应包含仅适用于卖方的数据。因此,我们想要存储的卖家的品质(属性)成为卖家表中的列。卖方表中的每一行(记录)代表一个单独的卖方。每个卖家都在卖家表中唯一标识,其唯一值存储在其主键列中,我们可以将其命名为seller_id。

A simplified version of such a table could look like this:

这种表的简化版本可能如下所示:

我应该将“quotation_request”作为我的数据库中的表格存储吗?

In a similar manner, the customer table should contain data only applicable to customers. The qualities (attributes) about customers that we wish to store become the columns in the customer table. Each row (record) in the customer table represents an individual customer. Each individual customer is uniquely identified in that table with a unique value in it's primary key column, which we can declare as customer_id.

以类似的方式,客户表应包含仅适用于客户的数据。我们希望存储的客户的质量(属性)成为客户表中的列。 customer表中的每一行(记录)代表一个客户。每个客户在该表中唯一标识,其主键列中包含唯一值,我们可以将其声明为customer_id。

A simplified version of this table:

此表的简化版本:

我应该将“quotation_request”作为我的数据库中的表格存储吗?

I'm guessing the business rules state that any customer is able to request any number of products, from any seller, any number of times...since surely any seller would want as many sales and customers as possible!

我猜测业务规则规定任何客户都可以从任何卖家那里多次请求任意数量的产品......因为任何卖家都希望尽可能多的销售和客户!

How can we express and record the interactions (relationship) between seller and customer?

我们如何表达和记录卖方与客户之间的互动(关系)?

This is done with a new kind of entity: a composite entity. It becomes a new table, having it's own primary key, and contains seller_id and customer_id as foreign keys. The foreign keys in this table connect (relate) the seller table to the customer table.

这是通过一种新的实体来完成的:一个复合实体。它成为一个新表,拥有自己的主键,并包含seller_id和customer_id作为外键。此表中的外键将卖方表连接(关联)到客户表。

We can name this new table quotation (if that is your preferred name). Each row of this table is intended to capture and record each and every individual transaction between a customer and a seller. The columns (attributes) of this table are the data that apply to a transaction between a customer and seller, such as amount or date of sale.

我们可以将此新表引用命名(如果这是您的首选名称)。该表的每一行旨在捕获和记录客户与卖方之间的每个单独交易。此表的列(属性)是适用于客户和卖方之间交易的数据,例如金额或销售日期。

A very simplified version of this composite entity:

这个复合实体的一个非常简化的版本:

我应该将“quotation_request”作为我的数据库中的表格存储吗?

Note that the foreign key values that exist in this table must already exist in their respective tables as a primary key value. That is, a foreign key value cannot be entered into this table unless it exists already as a primary key value in it's own table. This is important, and it is called referential integrity - it ensures that there is no record of a customer purchasing from a non-existent seller, etc.

请注意,此表中存在的外键值必须已作为主键值存在于其各自的表中。也就是说,除非外键值已作为其自己的表中的主键值存在,否则无法在该表中输入外键值。这很重要,它被称为参照完整性 - 它确保没有客户从不存在的卖家购买的记录等。

In the example above we can see that Builder B requested a quotation from Acme Construction in the amount of $3500.00. They then requested another quotation at another time for the amount of $1800.00. What else does it reveal? All existing customers have ordered something. Acme Lumber has not made a sale at all (yet), etc.

在上面的例子中,我们可以看到Builder B要求Acme Construction报价$ 3500.00。然后,他们在另一个时间要求另一个报价,金额为1800.00美元。它还揭示了什么?所有现有客户都订购了一些东西Acme Lumber尚未进行销售(等),等等。

A design such as this enables the database to store any number of transactions between sellers and customers. Likewise, it supports the addition of any number of new customers and sellers, even if they have not sold or purchased anything yet. Queries can be run that reveal which sellers have sold the most or least, and so on.

诸如此类的设计使数据库能够在卖方和客户之间存储任意数量的交易。同样,它支持添加任意数量的新客户和卖家,即使他们尚未出售或购买任何东西。可以运行查询以显示哪些卖家销售最多或最少,等等。

Good luck with your studies!

祝你学习顺利!

#1


0  

Without knowing all of the business rules that govern the requirements of this database, perhaps the following design will help to answer your question and explain a few concepts in the process.

在不了解管理此数据库要求的所有业务规则的情况下,以下设计可能有助于回答您的问题并解释该过程中的一些概念。

In database terms, an entity is a person, place, or thing about which we want to collect and store data. From your description we can already see two entities: seller and customer. This is important since the entities we identify conceptually become database tables in their own right.

在数据库术语中,实体是我们想要收集和存储数据的人,地点或事物。根据您的描述,我们已经可以看到两个实体:卖家和客户。这很重要,因为我们识别的实体在概念上本身就是数据库表。

The seller table should contain data applicable only to sellers. Thus, the qualities (attributes) about sellers that we want to store become columns in our seller table. Each row (record) in the seller table represents an individual seller. Each individual seller is uniquely identified in the seller table with a unique value stored in it's primary key column, which we can name seller_id.

卖方表应包含仅适用于卖方的数据。因此,我们想要存储的卖家的品质(属性)成为卖家表中的列。卖方表中的每一行(记录)代表一个单独的卖方。每个卖家都在卖家表中唯一标识,其唯一值存储在其主键列中,我们可以将其命名为seller_id。

A simplified version of such a table could look like this:

这种表的简化版本可能如下所示:

我应该将“quotation_request”作为我的数据库中的表格存储吗?

In a similar manner, the customer table should contain data only applicable to customers. The qualities (attributes) about customers that we wish to store become the columns in the customer table. Each row (record) in the customer table represents an individual customer. Each individual customer is uniquely identified in that table with a unique value in it's primary key column, which we can declare as customer_id.

以类似的方式,客户表应包含仅适用于客户的数据。我们希望存储的客户的质量(属性)成为客户表中的列。 customer表中的每一行(记录)代表一个客户。每个客户在该表中唯一标识,其主键列中包含唯一值,我们可以将其声明为customer_id。

A simplified version of this table:

此表的简化版本:

我应该将“quotation_request”作为我的数据库中的表格存储吗?

I'm guessing the business rules state that any customer is able to request any number of products, from any seller, any number of times...since surely any seller would want as many sales and customers as possible!

我猜测业务规则规定任何客户都可以从任何卖家那里多次请求任意数量的产品......因为任何卖家都希望尽可能多的销售和客户!

How can we express and record the interactions (relationship) between seller and customer?

我们如何表达和记录卖方与客户之间的互动(关系)?

This is done with a new kind of entity: a composite entity. It becomes a new table, having it's own primary key, and contains seller_id and customer_id as foreign keys. The foreign keys in this table connect (relate) the seller table to the customer table.

这是通过一种新的实体来完成的:一个复合实体。它成为一个新表,拥有自己的主键,并包含seller_id和customer_id作为外键。此表中的外键将卖方表连接(关联)到客户表。

We can name this new table quotation (if that is your preferred name). Each row of this table is intended to capture and record each and every individual transaction between a customer and a seller. The columns (attributes) of this table are the data that apply to a transaction between a customer and seller, such as amount or date of sale.

我们可以将此新表引用命名(如果这是您的首选名称)。该表的每一行旨在捕获和记录客户与卖方之间的每个单独交易。此表的列(属性)是适用于客户和卖方之间交易的数据,例如金额或销售日期。

A very simplified version of this composite entity:

这个复合实体的一个非常简化的版本:

我应该将“quotation_request”作为我的数据库中的表格存储吗?

Note that the foreign key values that exist in this table must already exist in their respective tables as a primary key value. That is, a foreign key value cannot be entered into this table unless it exists already as a primary key value in it's own table. This is important, and it is called referential integrity - it ensures that there is no record of a customer purchasing from a non-existent seller, etc.

请注意,此表中存在的外键值必须已作为主键值存在于其各自的表中。也就是说,除非外键值已作为其自己的表中的主键值存在,否则无法在该表中输入外键值。这很重要,它被称为参照完整性 - 它确保没有客户从不存在的卖家购买的记录等。

In the example above we can see that Builder B requested a quotation from Acme Construction in the amount of $3500.00. They then requested another quotation at another time for the amount of $1800.00. What else does it reveal? All existing customers have ordered something. Acme Lumber has not made a sale at all (yet), etc.

在上面的例子中,我们可以看到Builder B要求Acme Construction报价$ 3500.00。然后,他们在另一个时间要求另一个报价,金额为1800.00美元。它还揭示了什么?所有现有客户都订购了一些东西Acme Lumber尚未进行销售(等),等等。

A design such as this enables the database to store any number of transactions between sellers and customers. Likewise, it supports the addition of any number of new customers and sellers, even if they have not sold or purchased anything yet. Queries can be run that reveal which sellers have sold the most or least, and so on.

诸如此类的设计使数据库能够在卖方和客户之间存储任意数量的交易。同样,它支持添加任意数量的新客户和卖家,即使他们尚未出售或购买任何东西。可以运行查询以显示哪些卖家销售最多或最少,等等。

Good luck with your studies!

祝你学习顺利!