當前位置:首頁 » 編程語言 » 性別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 瀏覽:593
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:888
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:581
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:765
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:684
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1012
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:255
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:113
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:806
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:712