mysql数据库的增删改查
一对多关系表
1
1 | SHOW CREATE DATABASE test; |
2选择数据库test
1 | use test |
2建表
1 | CREATE TABLE book ( |
3插入
1 | INSERT INTO book_shelf (shelf_manager, shelf_position, record_time) |
2.
1 | SELECT * FROM book_shelf; |
3.
1 | INSERT INTO book (book_name, book_author, book_shelf, book_addtime) |
4.
1 | SELECT book_name, book_author, shelf_manager, shelf_position FROM book, book_shelf |
多对多关系
1建立数据库map
- 建立
1 | SHOW CREATE DATABASE map; |
- 选择数据库
1 | use map |
2建表
- 学生表
1 | CREATE TABLE student |
- 课程表
1 | CREATE TABLE course |
- 教师
1 | CREATE TABLE teacher |
3学生和课程多对多
- 建立学生和课程多对多的表
1 | CREATE TABLE course_student |
- 插入
1 | INSERT INTO student (stu_name, stu_class, stu_phone, record_time) |
- 查询学生表
1 | SELECT * FROM student; |
- 插入课程
1 | INSERT INTO course (course_name, teacher_id, record_time) |
- 查询学生和老师
1 |
- 插入
1 | INSERT INTO course_student (course_id, stu_id) VALUES (1,1),(1, 2),(2,1), (3, 1); |
- 选择课程名和学生名
1 | SELECT course_name,stu_name FROM course, student, course_student |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
