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

热点内容
macfd存储 发布:2025-07-04 12:16:11 浏览:237
QQ密码记不住了怎么办 发布:2025-07-04 12:01:40 浏览:113
android银行卡支付 发布:2025-07-04 11:39:00 浏览:570
数控编程点孔 发布:2025-07-04 11:21:20 浏览:662
安卓手机信号弱如何增强 发布:2025-07-04 11:09:01 浏览:757
安卓什么品牌带陀螺仪 发布:2025-07-04 11:08:59 浏览:593
服务器如何接入互联网 发布:2025-07-04 11:01:08 浏览:479
网站服务器数据库服务器 发布:2025-07-04 11:00:07 浏览:397
稀土开采需要哪些人员配置 发布:2025-07-04 10:59:57 浏览:465
少儿编程指引 发布:2025-07-04 10:59:05 浏览:623