Home > Database > Mysql Tutorial > How to design the table structure of the warehouse management system in MySQL to manage inventory price information?

How to design the table structure of the warehouse management system in MySQL to manage inventory price information?

WBOY
Release: 2023-10-31 09:39:11
Original
1138 people have browsed it

How to design the table structure of the warehouse management system in MySQL to manage inventory price information?

How to design the table structure of the warehouse management system in MySQL to manage inventory price information?

In the warehouse management system, the management of inventory prices is very important for the operation of the enterprise. In order to effectively manage inventory price information, when designing the table structure of the MySQL database, the following aspects need to be considered: warehouse management, product management, inventory management, and price management.

First, we need to create tables related to warehouse management. These tables need to record the basic information of the warehouse, such as warehouse name, address, contact information, etc. The following is the table creation statement for the warehouse table:

CREATE TABLE warehouse (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    address VARCHAR(200) NOT NULL,
    contact VARCHAR(50) NOT NULL
);
Copy after login

Next, we need to create tables related to product management. These tables need to record the basic information of the product, such as product name, specifications, units, etc. The following is the table creation statement for the product table:

CREATE TABLE product (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    specification VARCHAR(100),
    unit VARCHAR(20)
);
Copy after login

Then, we need to create tables related to inventory management. These tables need to record information about the goods in inventory, including inventory quantity, warehouse to which they belong, etc. The following is the table creation statement for the inventory table:

CREATE TABLE inventory (
    id INT AUTO_INCREMENT PRIMARY KEY,
    product_id INT,
    warehouse_id INT,
    quantity INT NOT NULL,
    FOREIGN KEY (product_id) REFERENCES product(id),
    FOREIGN KEY (warehouse_id) REFERENCES warehouse(id)
);
Copy after login

Finally, we need to create tables related to price management. These tables need to record the price information of the goods, including purchase price, sales price, etc. The following is the table creation statement of the price list:

CREATE TABLE price (
    id INT AUTO_INCREMENT PRIMARY KEY,
    product_id INT,
    purchase_price DECIMAL(10, 2),
    sale_price DECIMAL(10, 2),
    FOREIGN KEY (product_id) REFERENCES product(id)
);
Copy after login

In the above table structure design, the product table and warehouse table record the basic information of the product and warehouse respectively, the inventory table records the product inventory information, and the price list records Product price information. Through these tables, we can easily manage inventory price information.

The following is some sample code to show how to insert and query data into the above table:

Insert product data:

INSERT INTO product (name, specification, unit) VALUES ('苹果', '红富士', '个');
Copy after login

Insert warehouse data:

INSERT INTO warehouse (name, address, contact) VALUES ('仓库A', '北京市朝阳区', '1234567890');
Copy after login

Insert inventory data:

INSERT INTO inventory (product_id, warehouse_id, quantity) VALUES (1, 1, 100);
Copy after login

Insert price data:

INSERT INTO price (product_id, purchase_price, sale_price) VALUES (1, 5.00, 8.00);
Copy after login

Query products and corresponding inventory and price information:

SELECT p.id, p.name, p.specification, p.unit, i.quantity, pr.purchase_price, pr.sale_price
FROM product p
LEFT JOIN inventory i ON p.id = i.product_id
LEFT JOIN price pr ON p.id = pr.product_id;
Copy after login

Through the above table structure design and sample code , we can achieve effective management of inventory price information in the warehouse management system in MySQL.

The above is the detailed content of How to design the table structure of the warehouse management system in MySQL to manage inventory price information?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template