用SQLserver实现简单的学校数据库

1.创建数据库school,包含学生表(student)、教师表(teacher)和家长表
(parents)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.数据完整性
1)在student中,设定学生号为主键
2)在student中,要求性别只能输男女。
3) 在student中,要求年龄在在16到50之间(包含16和50)

3.录入数据每表不少于10条记录(请写出对应代码)。数据示例如下:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  1. 简单查询
    1)在student表中,采用列的中文别名方式显示学生的全部信息
    2)在student表中,查询年龄在23~24周岁之间的学生记录
    3)在student表中,按年龄的升序及降序排列
    4)在student表中,查询最前面的两条记录
    5)在student表中,查询名字以A开头的学生信息。

  2. 数据汇总
    1)在student表中,统计男女生人数
    2)查询teachers表中,教龄超过5年的老师的数量
    3)统计teachers表中,男老师和女老师的数量

  3. 多表查询

1)student表的学生编号、姓名和parents表中的家长编号与父亲名字显示出来
2)student表的学生编号、姓名teachers表中班主任姓名,职称显示出来

  1. 数据更新
    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', '男', 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值