当前位置:首页 » 编程语言 » 性别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

热点内容
密码锁坏了如何打开 发布:2025-05-15 11:30:19 浏览:836
怎样增加共享文件夹连接数量 发布:2025-05-15 11:24:50 浏览:961
安卓如何关闭单应用音量 发布:2025-05-15 11:22:31 浏览:351
抖音电脑后台服务器中断 发布:2025-05-15 11:11:59 浏览:307
sql2008服务器 发布:2025-05-15 11:03:27 浏览:306
我的世界pe服务器创造 发布:2025-05-15 10:51:17 浏览:608
移动端打吃鸡要什么配置 发布:2025-05-15 10:48:16 浏览:756
我的世界哪五个服务器被炸了 发布:2025-05-15 10:36:16 浏览:994
ehcache存储对象 发布:2025-05-15 10:35:31 浏览:528
搭建虚拟电脑的服务器 发布:2025-05-15 10:29:31 浏览:270