当前位置:首页 » 编程语言 » 性别sql

性别sql

发布时间: 2023-06-14 17:03:54

sql 性别 约束

1
创建sm数据库中的选课表sc,包含的列为学号、课程编号、成绩。
create
table
sc(
学号
varchar(10)
not
null,
--数据类型自己定
课程编号
varchar(10)
not
null,
成绩
decimal(3,
0)
)
2
用sql语句给表student的“学号”列添加主键约束。
alter
table
student
add
constraint
pkstudent
primary
key
(学号)
3
用sql语句给表student的“性别”列添加check约束。
alter
table
student
add
constraint
chkstudentsex
check
(
性别
=
'女'
or
性别
=
'男')
4
用sql语句给表course的“课程编号”
列添加主键约束。
alter
table
course
add
constraint
pkcourse
primary
key
(课程编号)
5
用sql语句给表course的“课程名称”
列添加unique约束。
alter
table
course
add
constraint
ukcourse
unique
(课程编号)
6
用sql语句给表sc的“学号”列添加外键约束,参照对象是表student的“学号”列。
alter
table
sc
add
constraint
fkscxh
foreign
key
(学号)
references
student
(学号)
7用sql语句给表sc的“课程编号”列添加外键约束,参照对象是表course的“课程编号”列。
alter
table
sc
add
constraint
fksckc
foreign
key
(课程编号)
references
course
(课程编号)
8用sql语句给表sc的“学号”“课程编号”列添加组合主键约束。
alter
table
sc
add
constraint
pksc
primary
key
(学号,课程编号)

❷ SQL查询,按性别显示学生信息,并分别汇总男生女生人数

如果性别在表Student中的列名称为“sex”的话,那么查询语句分别是:
按性别显示学生信息
Select * from Student order by sex
汇总学生人数
select sex,count(*) as cnt from student group by sex

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:550
制作脚本网站 发布:2025-10-20 08:17:34 浏览:833
python中的init方法 发布:2025-10-20 08:17:33 浏览:538
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:719
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:639
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:957
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:213
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:70
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:761
python股票数据获取 发布:2025-10-20 07:39:44 浏览:667