简体   繁体   English

具有相似列/属性的设计表

[英]Design table with similar columns/attributes

I have 2 forms, let's say a product_with_refund_form and product_without_refund_form. 我有2种表格,假设是product_with_refund_form和product_without_refund_form。 In table 1 I have these fields: 在表1中,我具有以下字段:

  • name 名称
  • transaction_number 交易号
  • status 状态
  • amount
  • cashier 出纳员

In the 2nd table I have: 在第二张表中,我有:

  • name 名称
  • amount
  • po_number 订单号

My question is, how do you design the table? 我的问题是,您如何设计桌子? Do I create each table for both of them or create 1 table with all similar fields, another table for product_with_refund_form that has fields unique to it then another table for product_without_refund_form. 我要为它们两个创建每个表,还是创建一个包含所有相似字段的表,为product_with_refund_form创建另一个具有唯一字段的表,然后为product_without_refund_form创建另一个表。

Instead of trying to work with two similar tables, why not combine the two into a single table. 与其尝试使用两个相似的表,不如将它们合并为一个表。

Note: 注意:

  • The Primary Key "ID" was added to uniquely identify each row with its Auto-Incremented value. 添加了主键“ ID”,以使用其自动递增的值唯一地标识每一行。
  • "isRefund" is used as a flag to tell the difference between the two forms. “ isRefund”用作标记来区分两种形式之间的区别。 This value could be any single character eg "y" or "n". 该值可以是任何单个字符,例如“ y”或“ n”。
  • Since the requirements do not mention an external "cashier" table, I kept this column a varchar field. 由于要求未提及外部“出纳”表,因此我将此列保留为varchar字段。

Product_Transactions - Field Names Product_Transactions-字段名称

id, name, transaction_number, status, amount, cashier, DateCreated, po_number, isRefund

Table Creation Code 表创建代码

CREATE TABLE Product_Transactions (`id` int AUTO_INCREMENT, `name` varchar(100), `status` varchar(10), 'amount' DECIMAL(10,2), 'cashier' varchar(100), 'DateCreated' TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 'po_number' varchar(100), 'isRefund' varchar(1), PRIMARY KEY (id))
;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM