国开_mysql数据库应用_形考3_数据增删改操作

阅读: 评论:0

2024年1月25日发(作者:)

国开_mysql数据库应用_形考3_数据增删改操作

实验步骤:

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;

国开_mysql数据库应用_形考3_数据增删改操作

本文发布于:2024-01-25 23:31:08,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/1706196668475.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数据   插入   语句   形考   数据库   步骤
留言与评论(共有 0 条评论)
   
验证码:
排行榜

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23