admin 管理员组

文章数量: 1184232


2024年4月17日发(作者:excel软件怎么下载)

实验步骤:

1. 打开MySQL Workbench并连接到你的数据库。

2. 按照实验3-1的插入操作,分别执行以下SQL语句,插入数据并检查结

果。

-- 插入Autoparts表的数据

INSERT INTO Autoparts (id, name, price) VALUES (1, '汽缸',

200);

INSERT INTO Autoparts (id, name, price) VALUES (2, '轮胎',

50);

-- 插入category表的数据

INSERT INTO category (id, name) VALUES (1, '汽车配件');

INSERT INTO category (id, name) VALUES (2, '食品');

-- 插入Client表的数据

INSERT INTO Client (id, name, email) VALUES (1, '张三',

'********************');

INSERT INTO Client (id, name, email) VALUES (2, '李四',

'****************');

-- 插入Clientkind表的数据

INSERT INTO Clientkind (id, name) VALUES (1, '个人');

INSERT INTO Clientkind (id, name) VALUES (2, '企业');

-- 插入shoppingcart表的数据

INSERT INTO shoppingcart (id, client_id, status) VALUES (1, 1,

'待支付');

INSERT INTO shoppingcart (id, client_id, status) VALUES (2, 2,

'待收货');

-- 插入Order表的数据

INSERT INTO Order (id, client_id, total_price) VALUES (1, 1,

200);

INSERT INTO Order (id, client_id, total_price) VALUES (2, 2,

50);

-- 插入order_has_Autoparts表的数据(需要先插入Autoparts表的数

据)

INSERT INTO order_has_Autoparts (order_id, autoparts_id,

quantity) VALUES (1, 1, 2);

INSERT INTO order_has_Autoparts (order_id, autoparts_id,

quantity) VALUES (2, 2, 1);

-- 插入Comment表的数据

INSERT INTO Comment (id, client_id, content) VALUES (1, 1, '商

品很好,很实用!');

INSERT INTO Comment (id, client_id, content) VALUES (2, 2, '物

流很快,很满意!');

3. 使用带Select的Insert语句完成汽车配件表Autoparts中数据的批量追加;

并通过select语句检查插入前后的记录情况。

-- 使用带Select的Insert语句批量插入Autoparts表的数据

INSERT INTO Autoparts (id, name, price)

SELECT id, name, price FROM (

SELECT 3 AS id, '发动机' AS name, 400 AS price UNION ALL

SELECT 4 AS id, '油箱' AS name, 200 AS price UNION ALL

SELECT 5 AS id, '方向盘' AS name, 100 AS price

) AS autoparts_temp;


本文标签: 插入 数据 语句 软件