“各种连接(等值连接、内连接、外连接、左连接、右连接、全连接)”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第26行: | 第26行: | ||
(20201106,'孙八',20,152); | (20201106,'孙八',20,152); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== 课程表和课程数据 ==== | ||
+ | <syntaxhighlight lang="sql"> | ||
+ | create table course( | ||
+ | cid int not null auto_increment, | ||
+ | cnum int not null primary key, | ||
+ | cname varchar(20) not null, | ||
+ | unique key course_num (cid) | ||
+ | ) engine = innodb auto_increment = 1 default charset = utf8; | ||
+ | |||
+ | INSERT INTO `sql`.`course` | ||
+ | (`cnum`, | ||
+ | `cname`) | ||
+ | VALUES | ||
+ | (101, '数据结构'), | ||
+ | (102, '编译原理'), | ||
+ | (103, '计算机网络'), | ||
+ | (105, '计算机组成原理'), | ||
+ | (106, '数据库'); | ||
</syntaxhighlight>等值连接/显式内连接 | </syntaxhighlight>等值连接/显式内连接 | ||
2022年11月3日 (四) 08:05的版本
演示数据
学生表和学生数据
CREATE TABLE `student` (
`sid` int(11) NOT NULL AUTO_INCREMENT,
`snum` int(11) NOT NULL,
`sname` varchar(20) NOT NULL,
`sage` tinyint(4) DEFAULT NULL,
`sclass` smallint(6) NOT NULL,
PRIMARY KEY (`snum`),
UNIQUE KEY `student_num` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `sql`.`student`
(`snum`,
`sname`,
`sage`,
`sclass`)
VALUES
(20201101,'张三',20,150),
(20201102,'李四',18,151),
(20201103,'王五',19,151),
(20201104,'赵六',18,150),
(20201105,'钱七',21,151),
(20201106,'孙八',20,152);
课程表和课程数据
create table course(
cid int not null auto_increment,
cnum int not null primary key,
cname varchar(20) not null,
unique key course_num (cid)
) engine = innodb auto_increment = 1 default charset = utf8;
INSERT INTO `sql`.`course`
(`cnum`,
`cname`)
VALUES
(101, '数据结构'),
(102, '编译原理'),
(103, '计算机网络'),
(105, '计算机组成原理'),
(106, '数据库');
等值连接/显式内连接
自然连接
外连接
内连接
全连接