创建computer表(编号、名称、品牌、重量、上市时间、价格); 添加5条测试数据 实现增册改查
时间: 2023-10-20 21:24:33 浏览: 87
创建computer表的SQL语句如下:
```sql
CREATE TABLE computer (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
brand VARCHAR(50) NOT NULL,
weight FLOAT NOT NULL,
launch_date DATE NOT NULL,
price DECIMAL(10,2) NOT NULL
);
```
添加5条测试数据的SQL语句如下:
```sql
INSERT INTO computer (name, brand, weight, launch_date, price)
VALUES ('MacBook Pro', 'Apple', 1.83, '2021-05-01', 1299.00),
('XPS 13', 'Dell', 1.2, '2021-02-15', 899.99),
('ZenBook Duo', 'Asus', 1.6, '2020-09-01', 1499.99),
('ThinkPad X1 Carbon', 'Lenovo', 1.09, '2021-03-01', 1499.00),
('Surface Laptop 4', 'Microsoft', 1.26, '2021-04-15', 999.00);
```
实现增删改查的SQL语句如下:
- 增加数据:
```sql
INSERT INTO computer (name, brand, weight, launch_date, price)
VALUES ('MateBook X Pro', 'Huawei', 1.33, '2021-06-01', 1399.00);
```
- 删除数据:
```sql
DELETE FROM computer WHERE id = 2;
```
- 修改数据:
```sql
UPDATE computer SET price = 1199.00 WHERE id = 3;
```
- 查询数据:
```sql
SELECT * FROM computer;
```
查询结果如下:
```
+----+------------------+-----------+--------+--------------+--------+
| id | name | brand | weight | launch_date | price |
+----+------------------+-----------+--------+--------------+--------+
| 1 | MacBook Pro | Apple | 1.83 | 2021-05-01 | 1299.00|
| 3 | ZenBook Duo | Asus | 1.60 | 2020-09-01 | 1499.99|
| 4 | ThinkPad X1 Carbon | Lenovo | 1.09 | 2021-03-01 | 1499.00|
| 5 | Surface Laptop 4 | Microsoft | 1.26 | 2021-04-15 | 999.00 |
| 6 | MateBook X Pro | Huawei | 1.33 | 2021-06-01 | 1399.00|
+----+------------------+-----------+--------+--------------+--------+
```
阅读全文