drop database if exists mydb;
create database mydb;
use mydb;
create table class(
cid int primary key auto_increment,
cname varchar(20)
);
create table student(
sid varchar(20) primary key,
sname varchar(20),
sage int,
ssex char(2),
cid int,
foreign key(cid) references class(cid)
);
insert into class values(null,'j211001');
insert into class values(null,'j211002');
insert into student values
('1001','张三',20,'男',1),
('1002','李四',18,'女',2),
('1003','王五',22,'男',1);
select * from class;
select * from student;
#查询大于18岁的信息
select * from student where sage>18;
#查询18岁到20岁的信息
select * from student where sage>=18 and sage<=20;
#查询20岁以上的男生
select * from student where sage>18 and ssex='男';
#查询名字中以张开头的名字
数据库写法
最新推荐文章于 2023-05-29 17:25:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)