qfedu-linux-advanced-level/day9/homework/h5.sql

69 lines
1.9 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
2.
3. 创建个人图片集表 images
表结构为: 图片编号 img_id, 标题 title, 宽度 width, 高度 height
【要求】为不同人员分别添加10条图片集记录
*/
-- 进入 bookdb 数据库
USE bookdb;
-- 创建个人图片集表 images
CREATE TABLE IF NOT EXISTS
images(
img_id INT PRIMARY KEY,
title VARCHAR(50),
width INT,
height INT,
user_id INT COMMENT '所属用户id',
FOREIGN KEY (user_id) REFERENCES login(login_id)
);
-- 为不同人员添加10条图片集记录
INSERT INTO images (img_id, title, width, height, user_id) VALUES
-- 1001 用户图集
(1, 'Image Set 1', 800, 600, 1001),
(2, 'Image Set 2', 1024, 768, 1001),
(3, 'Image Set 3', 1280, 720, 1001),
(4, 'Image Set 4', 800, 600, 1001),
(5, 'Image Set 5', 1024, 768, 1001),
(6, 'Image Set 6', 1280, 720, 1001),
(7, 'Image Set 7', 800, 600, 1001),
(8, 'Image Set 8', 1024, 768, 1001),
(9, 'Image Set 9', 1280, 720, 1001),
(10, 'Image Set 10', 800, 600, 1001),
-- 1002 用户图集
(11, 'Image Set 11', 800, 600, 1002),
(12, 'Image Set 12', 1024, 768, 1002),
(13, 'Image Set 13', 1280, 720, 1002),
(14, 'Image Set 14', 800, 600, 1002),
(15, 'Image Set 15', 1024, 768, 1002),
(16, 'Image Set 16', 1280, 720, 1002),
(17, 'Image Set 17', 800, 600, 1002),
(18, 'Image Set 18', 1024, 768, 1002),
(19, 'Image Set 19', 1280, 720, 1002),
(20, 'Image Set 20', 800, 600, 1002),
-- 1003 用户图集
(21, 'Image Set 21', 800, 600, 1003),
(22, 'Image Set 22', 1024, 768, 1003),
(23, 'Image Set 23', 1280, 720, 1003),
(24, 'Image Set 24', 800, 600, 1003),
(25, 'Image Set 25', 1024, 768, 1003),
(26, 'Image Set 26', 1280, 720, 1003),
(27, 'Image Set 27', 800, 600, 1003),
(28, 'Image Set 28', 1024, 768, 1003),
(29, 'Image Set 29', 1280, 720, 1003),
(30, 'Image Set 30', 800, 600, 1003);
-- 显示内容
DESCRIBE images;
SELECT
img_id AS '图片编号',
title AS '标题',
width AS '宽度',
height AS '高度',
user_id AS '所属用户id'
FROM images;