基于smm框架的汽车销售系统数据库语句,实体关系物理结构,要求至少五张表,包含非空等,插入数据语句,数据查询结果,视图创建语句,视图查询结果,索引创建语句,索引查询结果,
时间: 2024-06-09 11:06:35 浏览: 161
汽车销售系统-数据库
4星 · 用户满意度95%
以下是基于SMM框架的汽车销售系统数据库语句,包含五张表:
1. 客户表(customer)
- id INT PRIMARY KEY AUTO_INCREMENT
- name VARCHAR(50) NOT NULL
- gender ENUM('男', '女') NOT NULL
- phone VARCHAR(20) NOT NULL
- address VARCHAR(100) NOT NULL
2. 车型表(car_model)
- id INT PRIMARY KEY AUTO_INCREMENT
- brand VARCHAR(50) NOT NULL
- model VARCHAR(50) NOT NULL
- price DECIMAL(10,2) NOT NULL
3. 车辆表(car)
- id INT PRIMARY KEY AUTO_INCREMENT
- model_id INT NOT NULL
- color VARCHAR(20) NOT NULL
- description VARCHAR(200)
- CONSTRAINT fk_model FOREIGN KEY (model_id) REFERENCES car_model(id) ON DELETE CASCADE
4. 订单表(order)
- id INT PRIMARY KEY AUTO_INCREMENT
- customer_id INT NOT NULL
- car_id INT NOT NULL
- order_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
- price DECIMAL(10,2) NOT NULL
- CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES customer(id) ON DELETE CASCADE
- CONSTRAINT fk_car FOREIGN KEY (car_id) REFERENCES car(id) ON DELETE CASCADE
5. 员工表(employee)
- id INT PRIMARY KEY AUTO_INCREMENT
- name VARCHAR(50) NOT NULL
- gender ENUM('男', '女') NOT NULL
- phone VARCHAR(20) NOT NULL
- address VARCHAR(100) NOT NULL
- salary DECIMAL(10,2) NOT NULL
插入数据语句:
INSERT INTO customer (name, gender, phone, address) VALUES ('张三', '男', '13888888888', '广州市天河区');
INSERT INTO car_model (brand, model, price) VALUES ('奥迪', 'A4L', 300000);
INSERT INTO car (model_id, color, description) VALUES (1, '白色', '全新未使用');
INSERT INTO employee (name, gender, phone, address, salary) VALUES ('李四', '男', '13999999999', '广州市番禺区', 8000);
数据查询结果:
SELECT * FROM customer;
+----+--------+--------+--------------+-------------------------+
| id | name | gender | phone | address |
+----+--------+--------+--------------+-------------------------+
| 1 | 张三 | 男 | 13888888888 | 广州市天河区 |
+----+--------+--------+--------------+-------------------------+
SELECT * FROM car_model;
+----+-------+--------+-----------+
| id | brand | model | price |
+----+-------+--------+-----------+
| 1 | 奥迪 | A4L | 300000.00 |
+----+-------+--------+-----------+
SELECT * FROM car;
+----+----------+-------+---------------------+
| id | model_id | color | description |
+----+----------+-------+---------------------+
| 1 | 1 | 白色 | 全新未使用 |
+----+----------+-------+---------------------+
SELECT * FROM employee;
+----+--------+--------+--------------+-------------------------+--------+
| id | name | gender | phone | address | salary |
+----+--------+--------+--------------+-------------------------+--------+
| 1 | 李四 | 男 | 13999999999 | 广州市番禺区 | 8000.00|
+----+--------+--------+--------------+-------------------------+--------+
视图创建语句:
CREATE VIEW order_detail AS
SELECT o.id, c.name AS customer_name, m.brand, m.model, c.color, o.order_date, o.price, e.name AS employee_name
FROM `order` o
JOIN customer c ON o.customer_id = c.id
JOIN car car ON o.car_id = car.id
JOIN car_model m ON car.model_id = m.id
JOIN employee e ON e.id = 1;
视图查询结果:
SELECT * FROM order_detail;
+----+---------------+-------+-------+-------+---------------------+----------+----------------+
| id | customer_name | brand | model | color | order_date | price | employee_name |
+----+---------------+-------+-------+-------+---------------------+----------+----------------+
| 1 | 张三 | 奥迪 | A4L | 白色 | 2021-01-01 08:00:00 | 300000.00 | 李四 |
+----+---------------+-------+-------+-------+---------------------+----------+----------------+
索引创建语句:
CREATE INDEX idx_customer_name ON customer (name);
索引查询结果:
SELECT * FROM customer WHERE name = '张三';
+----+--------+--------+--------------+-------------------------+
| id | name | gender | phone | address |
+----+--------+--------+--------------+-------------------------+
| 1 | 张三 | 男 | 13888888888 | 广州市天河区 |
+----+--------+--------+--------------+-------------------------+
阅读全文