1.创建数据库school,包含学生表(student)、教师表(teacher)和家长表
(parents)
2.数据完整性
1)在student中,设定学生号为主键
2)在student中,要求性别只能输男女。
3) 在student中,要求年龄在在16到50之间(包含16和50)
3.录入数据每表不少于10条记录(请写出对应代码)。数据示例如下:
-
简单查询
1)在student表中,采用列的中文别名方式显示学生的全部信息
2)在student表中,查询年龄在23~24周岁之间的学生记录
3)在student表中,按年龄的升序及降序排列
4)在student表中,查询最前面的两条记录
5)在student表中,查询名字以A开头的学生信息。 -
数据汇总
1)在student表中,统计男女生人数
2)查询teachers表中,教龄超过5年的老师的数量
3)统计teachers表中,男老师和女老师的数量 -
多表查询
1)student表的学生编号、姓名和parents表中的家长编号与父亲名字显示出来
2)student表的学生编号、姓名teachers表中班主任姓名,职称显示出来
- 数据更新
1)在teachers表中插入一条老师编号为999的教师信息记录
2)将老师编号为999的老师信息的教龄增加3年
3)将老师编号为999的老师信息删除
drop table student
drop table teacher
drop table parents
--create database school
--创建学生表
--第一点,三个基本表的创建
create table student
(
Id int primary key,
name varchar(50) NOT NULL,
gender char(2) default('男'),
age smallint not null,
grade smallint not null,
class smallint not null,
teacher_id int not null,
parents_id int not null,
constraint ck_1 check(age>=16),
constraint ck_3 check(age<=50),
constraint ck_2 check(gender='男' or gender='女')
)
--第二点,修改主键的约束,已经在定义中完成
create table teacher
(
Id int primary key ,
name varchar(50) NOT NULL,
gender char(2) default('男'),
age smallint not null,
subjects char(20) not null,
teacher_age int not null,
position char(20)
)
--家长信息表
create table parents
(
id int,
father varchar(50),
mother varchar(50),
f_talephone char(20),
m_talephone char(20),
phone char(20),
f_company varchar(50),
m_company varchar(50),
f_position char(20),
m_position char(20)
)
--第三点,插入数据
insert into student (id, name, gender, age, grade, class, teacher_id, parents_id)
values (2006001, 'alice', '女', 23, 1, 2, 102, 2001)
insert into student (id, name, gender, age, grade, class, teacher_id, parents_id)
values (2006002, 'rose', '男',