数据库系统概论实验报告
实验一熟悉SQL一实验目的1,熟悉SQL的工作环境;2,在SQL中,使用SQL语言并创建基本表,正确录入数据。二实验内容三实验代码1创建“学生”表stude
tcreatetablestude
ts
ochar9primarykeys
amechar20u
iquessexchar2sagesmalli
tsdeptchar202创建“课程”表coursecreatetablecoursec
ochar4primarykeyc
amechar40cp
ochar4ccreditsmalli
tforeig
keycp
orefere
cescoursec
o3创建学生选课表SCcreatetablescs
ochar9c
ochar4gradesmalli
tprimarykeys
oc
oforeig
keys
orefere
cesstude
ts
oforeig
keyc
orefere
cescoursec
o
Stude
t
s
o200215121200215122200215123200215125s
ame李勇刘晨王敏张立ssex男女女男sage20191819sdeptCSCSMACS
fCourse
c
o1234567c
ame数据库数学信息系统操作系统数据结构数据处理Pascal言语6167cp
o5ccredit4243424
Sc
s
o200215121200215121200215121200215122200215122c
o12323grade9285889080
修改基本表
表增加“入学时间”其数据类型为日期型。向Stude
t表增加“入学时间”列,其数据类型为日期型。ALTERTABLEStude
tADDS_e
tra
ceDATE将年龄的数据类型由字符型(假设原来的数据类型是字符型改为整数。字符型)将年龄的数据类型由字符型(假设原来的数据类型是字符型)改为整数。ALTERTABLEStude
tALTERCOLUMNSageINT;;增加课程名称必须取唯一值的约束条件。增加课程名称必须取唯一值的约束条件。ALTERTABLECourseADDUNIQUE(C
ame)();
删除基本表
删除stude
t表Droptablestude
tcascade若表上建有视图,时表不能删除,时可以删除表,若表上建有视图,选择restrict时表不能删除,cascade时可以删除表,视图也自动被删除Createviewis_stude
tAsSelects
os
amesageFromstude
tWheresdept’is’Droptablestude
trestricterrorca
otdroptablestude
tbecauseotherobjectsdepe
do
itDroptablestude
tcascade
oticedropcascadestoviewis_stude
tSelectfromis_stude
terrorrelatio
“is_stude
t”does
otexit
f数据查询单表查询
一选择表中的若干列1查询指定列1)查询全体学生的学号和姓名:Selects
os
ameFromstude
t
2)查询全体学生的姓名,学号,所在系Selects
ames
osdeptFromstude
t
2查询全部列1)查询全体学生的详细记录SelectFromstude
t
或:Selects
os
amessexsagesdeptFromstude
t
f3查询经过计算的值1查询全体学生的姓名及其出生年份Selects
ame2004sageFromstude
t
2查询全体学生的姓名,出生年份和所在的院系,要求用小写字母表示所有系名。Selects
ame’yearofbirth’2004sagelowersdeptFromstude
t
或:Selects
amer