-- 创建顾客表: CREATE TABLE Customer ( Customer_id VARCHAR(50) PRIMARY KEY, Customer_name VARCHAR(50), Customer_gender VARCHAR(10), Customer_phone VARCHAR(20), Customer_address VARCHAR(100) ); -- 创建商品表: CREATE TABLE Product ( Product_id INT PRIMARY KEY, Product_name VARCHAR(50), Product_type VARCHAR(20), Product_price DECIMAL(10, 2), Supplier_id VARCHAR(50), stock_num INT ); -- 创建员工表: CREATE TABLE Employee ( Employee_id INT PRIMARY KEY, Employee_name VARCHAR(50), Employee_gender VARCHAR(10), Employee_phone VARCHAR(20), Employee_position VARCHAR(50) ); -- 创建供货商表: CREATE TABLE Supplier ( Supplier_id VARCHAR(50) PRIMARY KEY, Product_list VARCHAR(50), Supplier_name VARCHAR(50), Supplier_contact VARCHAR(50), Supplier_phone VARCHAR(20), Supplier_address VARCHAR(100) ); -- 创建销售表: CREATE TABLE Sale ( Sale_id INT AUTO_INCREMENT PRIMARY KEY, Product_id INT, Order_id INT, Order_date DATE, Employee_id INT, Customer_id VARCHAR(50), Sale_num INT, Sale_amount DECIMAL(10, 2), FOREIGN KEY (Product_id) REFERENCES Product (Product_id), FOREIGN KEY (Employee_id) REFERENCES Employee (Employee_id), FOREIGN KEY (Customer_id) REFERENCES Customer (Customer_id) ); -- 创建库存表: CREATE TABLE Stock ( Product_id INT PRIMARY KEY, Stock_num INT, indata DATE, outdata DATE, FOREIGN KEY (Product_id) REFERENCES Product (Product_id) ); -- 创建订单表: CREATE TABLE Order_dd ( Order_id INT AUTO_INCREMENT PRIMARY KEY, Product_id INT, Product_num INT, Customer_id VARCHAR(50), Order_date DATE, Order_price DECIMAL(10, 2), Order_status ENUM('待发货', '已发货', '待确认','已完成') );向以上代码中商品表插入50个数据,同时再库存表中插入50个数据与商品对应
时间: 2024-03-10 22:45:34 浏览: 81
MySql学习day03:数据表之间的连接、查询详解
给商品表插入50个数据的SQL语句如下:
```
INSERT INTO Product (Product_id, Product_name, Product_type, Product_price, Supplier_id, stock_num)
VALUES (1, '商品1', '类型1', 10.00, 'S1', 100),
(2, '商品2', '类型1', 20.00, 'S2', 200),
(3, '商品3', '类型1', 30.00, 'S3', 300),
...
(48, '商品48', '类型5', 480.00, 'S3', 4800),
(49, '商品49', '类型5', 490.00, 'S4', 4900),
(50, '商品50', '类型5', 500.00, 'S5', 5000);
```
给库存表插入50个数据的SQL语句如下:
```
INSERT INTO Stock (Product_id, Stock_num, indata, outdata)
VALUES (1, 100, '2021-01-01', NULL),
(2, 200, '2021-01-02', NULL),
(3, 300, '2021-01-03', NULL),
...
(48, 4800, '2021-02-16', NULL),
(49, 4900, '2021-02-17', NULL),
(50, 5000, '2021-02-18', NULL);
```
以上SQL语句中,`Product_id`和`Stock_num`分别对应商品表和库存表中的商品编号和库存数量,`indata`和`outdata`分别表示入库时间和出库时间,这里将所有数据都设置为入库时间。同时,为了确保商品表和库存表中数据的对应性,需要保证两张表中的商品编号一致。
阅读全文