-- 景点表 CREATE TABLE spot ( spot_id INT PRIMARY KEY, spot_name VARCHAR(100), city VARCHAR(100), description TEXT, rating FLOAT ); -- 旅游者表 CREATE TABLE traveler ( traveler_id INT PRIMARY KEY, name VARCHAR(100), age INT, gender ENUM('Male', 'Female'), nationality VARCHAR(100), contact VARCHAR(100) ); -- 游记表 CREATE TABLE travelogue ( travelogue_id INT PRIMARY KEY, title VARCHAR(100), content TEXT, publish_time DATETIME, author_id INT, FOREIGN KEY (author_id) REFERENCES traveler(traveler_id) ); -- 攻略表 CREATE TABLE strategy ( strategy_id INT PRIMARY KEY, title VARCHAR(100), content TEXT, publish_time DATETIME, author_id INT, FOREIGN KEY (author_id) REFERENCES traveler(traveler_id) ); -- 评论表 CREATE TABLE comment ( comment_id INT PRIMARY KEY, content TEXT, comment_time DATETIME, spot_id INT, commenter_id INT, FOREIGN KEY (spot_id) REFERENCES spot(spot_id), FOREIGN KEY (commenter_id) REFERENCES traveler(traveler_id) ); -- 收藏夹表 CREATE TABLE collection ( collection_id INT PRIMARY KEY, collection_name VARCHAR(100), creator_id INT, FOREIGN KEY (creator_id) REFERENCES traveler(traveler_id) ); -- 收藏明细表 CREATE TABLE collection_detail ( detail_id INT PRIMARY KEY, collection_id INT, spot_id INT, FOREIGN KEY (collection_id) REFERENCES collection(collection_id), FOREIGN KEY (spot_id) REFERENCES spot(spot_id) ); 我要给上述表中每张表插入5条 数据 mysql8.0代码
时间: 2024-04-19 19:27:14 浏览: 146
以下是向每张表插入5条数据的MySQL 8.0代码示例:
```sql
-- 向spot表插入5条数据
INSERT INTO spot (spot_id, spot_name, city, description, rating)
VALUES
(1, '景点A', '城市A', '这是景点A的描述', 4.5),
(2, '景点B', '城市B', '这是景点B的描述', 4.2),
(3, '景点C', '城市C', '这是景点C的描述', 3.8),
(4, '景点D', '城市D', '这是景点D的描述', 4.0),
(5, '景点E', '城市E', '这是景点E的描述', 4.7);
-- 向traveler表插入5条数据
INSERT INTO traveler (traveler_id, name, age, gender, nationality, contact)
VALUES
(1, '旅游者A', 25, 'Male', '国籍A', '联系方式A'),
(2, '旅游者B', 30, 'Female', '国籍B', '联系方式B'),
(3, '旅游者C', 28, 'Male', '国籍C', '联系方式C'),
(4, '旅游者D', 35, 'Female', '国籍D', '联系方式D'),
(5, '旅游者E', 22, 'Male', '国籍E', '联系方式E');
-- 向travelogue表插入5条数据
INSERT INTO travelogue (travelogue_id, title, content, publish_time, author_id)
VALUES
(1, '游记A', '这是游记A的内容', '2021-01-01 10:00:00', 1),
(2, '游记B', '这是游记B的内容', '2021-02-02 11:00:00', 2),
(3, '游记C', '这是游记C的内容', '2021-03-03 12:00:00', 3),
(4, '游记D', '这是游记D的内容', '2021-04-04 13:00:00', 4),
(5, '游记E', '这是游记E的内容', '2021-05-05 14:00:00', 5);
-- 向strategy表插入5条数据
INSERT INTO strategy (strategy_id, title, content, publish_time, author_id)
VALUES
(1, '攻略A', '这是攻略A的内容', '2021-01-01 10:00:00', 1),
(2, '攻略B', '这是攻略B的内容', '2021-02-02 11:00:00', 2),
(3, '攻略C', '这是攻略C的内容', '2021-03-03 12:00:00', 3),
(4, '攻略D', '这是攻略D的内容', '2021-04-04 13:00:00', 4),
(5, '攻略E', '这是攻略E的内容', '2021-05-05 14:00:00', 5);
-- 向comment表插入5条数据
INSERT INTO comment (comment_id, content, comment_time, spot_id, commenter_id)
VALUES
(1, '这是评论1的内容', '2021-01-01 10:00:00', 1, 1),
(2, '这是评论2的内容', '2021-02-02 11:00:00', 1, 2),
(3, '这是评论3的内容', '2021-03-03 12:00:00', 2, 3),
(4, '这是评论4的内容', '2021-04-04 13:00:00', 3, 4),
(5, '这是评论5的内容', '2021-05-05 14:00:00', 4, 5);
-- 向collection表插入5条数据
INSERT INTO collection (collection_id, collection_name, creator_id)
VALUES
(1, '收藏夹A', 1),
(2, '收藏夹B', 2),
(3, '收藏夹C', 3),
(4, '收藏夹D', 4),
(5, '收藏夹E', 5);
-- 向collection_detail表插入5条数据
INSERT INTO collection_detail (detail_id, collection_id, spot_id)
VALUES
(1, 1, 1),
(2, 1, 2),
(3, 2, 3),
(4, 2, 4),
(5, 3, 5);
```
使用以上代码,你可以向每张表中插入5条数据。注意要根据实际需求修改属性值。这样你就可以进行增、删、改、查等操作,并对数据库的安全性、触发器和存储过程进行验证。
阅读全文