当前位置:网站首页>数据库实验一:数据定义实验指导
数据库实验一:数据定义实验指导
2022-06-12 05:43:00 【LEO-max】
实验一 数据定义实验指导
(数据库模式设计及建立)
1.实验目的
(1)让学生自己完成数据库模式的设计。
(2)用SQL命令建立数据库表。
(3)用可视化环境建立数据库表。
2.实验内容
(1)定义数据表。
(2)修改表结构:增添字段,修改字段类型。
(3)删除表结构。
3.实验要求
(1)建立学生数据库模式。
学生表:student (sno, sname, ssex, sage, sdept)
学生 学号 姓名 性别 年龄 所在系
sno 长度为4的字符串
sname 长度为8的字符串
ssex 长度为2的字符串
sage 短整数
sdept 长度为10的字符串
其中sno为主码。
CREATE TABLE IF NOT EXISTS student(
sno VARCHAR(4) NOT NULL PRIMARY KEY COMMENT '学号,主键',
sname VARCHAR(8) NOT NULL COMMENT '姓名',
ssex VARCHAR(2) NOT NULL COMMENT '性别',
sage TINYINT(3) UNSIGNED DEFAULT 0 COMMENT '年龄',
sdept VARCHAR(10) NOT NULL COMMENT '所在系'
)ENGINE=InnoDB CHARSET=UTF8 COMMENT='学生表';
课程表:course ( cno, cname)
课程 课程号 课程名 学分
cno 长度为4的字符串
cname 长度为10的字符串
credit 短整数
其中cno为主码。
CREATE TABLE IF NOT EXISTS course(
cno VARCHAR(4) NOT NULL PRIMARY KEY COMMENT '课程号,主键',
cname VARCHAR(10) NOT NULL COMMENT '课程名',
credit TINYINT(3) UNSIGNED DEFAULT 0 COMMENT '学分'
)ENGINE=InnoDB CHARSET=UTF8 COMMENT='课程表';
选课表: sc (sno, cno, cname, grade)
选课 学号 课程号 课程名 成绩
sno 长度为4的字符串
cno 长度为4的字符串
cname 长度为10的字符串
grade 短整数
其中(sno, cno) 为主码;sno为外码和student表对应;cno为外码和course表对应;
grade的值或空或为0—100之间。
CREATE TABLE sc(
sno VARCHAR(4),
cno VARCHAR(4),
cname VARCHAR(10),
grade INT CHECK(grade BETWEEN 0 AND 100),
PRIMARY KEY (sno,cno),
FOREIGN KEY (sno) REFERENCES student(sno) ON DELETE CASCADE,
FOREIGN KEY (cno) REFERENCES course(cno)
)ENGINE=InnoDB CHARSET=UTF8;
(2)修改数据表结构
在课程表中增加一个credit字段,表示学分,类型为短整形。
从选课表中删除cname字段。
ALTER TABLE course MODIFY credit TINYINT COMMENT '学分';
ALTER TABLE sc drop cname;
(3)撤销数据表。建立一个临时表,然后再把它撤销。
CREATE TABLE TEMP(
cno VARCHAR(4) PRIMARY KEY,
cname VARCHAR(10),
credit TINYINT
);
DROP TABLE temp;
要求写出实验一的全部代码,
注意:
1.全部代码
2.代码的全角半角
3.格式规整,便于批阅
边栏推荐
- Win10 desktop unlimited refresh
- 16. 最接近的三数之和
- The application could not be installed: INSTALL_FAILED_TEST_ONLY
- [JS knowledge] easily understand JS anti shake and throttling
- [Speech] 如何根据不同国家客制化ring back tone
- XML parameter schema, the same MTK SW version is compatible with two different sets of audio parameters
- Tabulation skills and matrix processing skills
- Execute sh script to prompt "[[: not found" solution. The difference between Bash and sh
- China's alternative sports equipment market trend report, technology dynamic innovation and market forecast
- 16. 最接近的三數之和
猜你喜欢

Go interface oriented programming practice

Introduction to thread pool: ThreadPoolExecutor

BlockingQueue interface introduction

TCP and UDP introduction

登录验证过滤器

16. sum of the nearest three numbers

yolov5

WiFi protocol and ieee905 protocol learning details

网络加速谁更猛?CDN领域再现新王者

Performance test - GTI application service performance monitoring platform
随机推荐
[Speech] 如何根据不同国家客制化ring back tone
Win10 desktop unlimited refresh
分公司负责人需要承担的法律责任
Deep understanding of asynchronous programming
Laravel8 when search
Why can't NAND flash be used as RAM while nor flash can
Performance test - performance test tool analysis
flex/fixed上中下(移動端)
Identification of campus green plants based on tensorflow
AddUser add user and mount hard disk
Research Report on market supply and demand and strategy of China's digital camera lens industry
17. print from 1 to the maximum n digits
Vivado HLS introductory notes
Introduction to thread pool: ThreadPoolExecutor
Flex / fixed Upper, Middle and Lower (Mobile end)
Why should state-owned enterprises go public
43. Number of occurrences of 1 in 1 ~ n integers
19. regular expression matching
Thesis reading_ Figure neural network gin
Selenium crawler automatically captures TOEFL test position of NEEA website