当前位置:网站首页>数据库实验报告(一)
数据库实验报告(一)
2022-07-01 10:42:00 【Billy Miracle】
一、 实验目的
理解和掌握数据库DDL语言,能够使用SQL DDL语句创修改和删除数据库、模式和表。
二、 实验内容
用SQL定义语句创建符合如下条件的表C-1到C-4(注意各种完整性约束)
表C-1 Student表结构
列名 说明 数据类型 约束
Sno 学号 普通编码定长字符串,长度为7 主键
Sname 姓名 普通编码定长字符串,长度为10
Ssex 性别 普通编码定长字符串,长度为2
Sage 年龄 微整型(tinyint)
Sdept 所在系 普通编码不定长字符串,长度为20
Sid 身份证号 普通编码定长字符串,长度为10
Sdate 入学日期 日期
表C-2 Course表结构
列名 说明 数据类型 约束
Cno 课程号 普通编码定长字符串,长度为10 主键
Cname 课程名 普通编码不定长字符串,长度为20
Credit 学时数 整型
Semester 学分 小整型
表C-3 SC表结构
列名 说明 数据类型 约束
Sno 学号 普通编码定长字符串,长度为7 主键,引用Student的外键
Cno 课程号 普通编码定长字符串,长度为10 主键,引用Course的外键
Grade 成绩 小整型
表C-4 Teacher表结构
列名 说明 数据类型 约束
Tno 教师号 普通编码定长字符串,长度为8
Tname 教师名 普通编码定长字符串,长度为10
Salary 工资 定点小数,小数点前4位,小数点后2位
表C-1 Student表数据
学号 姓名 性别 年龄 系别 身份证号 入学日期
0811101 李勇 男 21 计算机系
0811102 刘晨 男 20 计算机系
0811103 王敏 女 20 计算机系
0811104 张小红 女 19 计算机系
0821101 张立 男 20 信息管理系
0821102 吴宾 女 19 信息管理系
0821103 张海 男 20 信息管理系
0831101 钱小平 女 21 通信工程系
0831102 王大力 男 20 通信工程系
0831103 张姗姗 女 19 通信工程系
表C-2 Course表中的记录
Cno Cname Credit Semester
C001 高等数学 4 1
C002 大学英语 3 1
C003 大学英语 3 2
C004 计算机文化学 2 2
C005 VB 2 3
C006 数据库基础 4 5
C007 数据结构 4 4
C008 计算机网络 4 4
表C-3 SC表中的记录
Sno Cno Grade
0811101 C001 96
0811101 C002 80
0811101 C003 84
0811101 C005 62
0811102 C001 92
0811102 C002 90
0811102 C004 84
0821102 C001 76
0821102 C004 86
0821102 C005 73
0821102 C007 NULL
0821103 C001 50
0821103 C004 80
0831101 C001 50
0831101 C004 80
0831102 C007 NULL
0831103 C004 78
0831103 C005 65
0831103 C007 NULL
表C-4 Teacher表中的记录
Tno Tname Salary
T001 张美霞 5000
T002 王洪林 5500
T003 李丽芬 4800
T004 周良水 6000
T005 吴翔 7000
三、实验环境
MySQL、Navicat 15 for MySQL
四、实验前准备
实验数据,写在了实验内容里面。
五、 实验步骤
先创建数据库:
Creat Database
接下来创建学生表:
创建课表:
创建选课表,以及两个外键(Foreign Key),分别关联student表的Sno和course表的Cno:
创建教师表:
接下来我们来看一下每个表的设计:



接下来添加数据:
因为学生表数据有两列没有,所以要写上每一个value对应的列。
课表数据:
选课表数据:
教师表数据:
接下来练习了有关用户的几个操作:
约束的学习:
直接放上学习的代码啦:







六、 实验结果
student、course、sc、teacher几个表创建完成,期望数据添加成功。
有关完整性的使用:创建时使用主键约束
更改学生姓名,使其非空:



边栏推荐
- Project0: Games
- Kotlin 协程调度切换线程是时候解开真相了
- 12.Gateway新一代网关
- CentOS configures discuz prompt, please check whether the MySQL module is loaded correctly
- 新一代云原生数据库的设计与实践
- Does anyone know why? The table structure is the source table MySQL CDC that has just been directly copied
- 商城小程序源码开源版-可二开
- CCNP Part XII BGP (IV)
- Guys, how to export iceberg data to MySQL? What tools are there? Neither sqoop nor dataX
- Recommend a JSON visualization tool artifact!
猜你喜欢

12款大家都在用的产品管理平台

基于Matlab的开环Buck降压斩波电路Simulink仿真电路模型搭建

Matplotlib数据可视化基础

预制菜迎来“黄金时代”,谁能领跑下一个万亿市场

新品大揭秘!雅迪冠能 3 多元产品矩阵,满足全球用户出行需求

Wireshark TS | confusion between fast retransmission and out of sequence

Lack of comparator, operational amplifier to save the field! (the op amp is recorded as a comparator circuit)

Error: missing revert data in call exception
![C [byte array] and [hexadecimal string] mutual conversion - codeplus series](/img/d2/dad88f53701c7cd7638bd4983cbb4b.png)
C [byte array] and [hexadecimal string] mutual conversion - codeplus series

Programmers want to go to state-owned enterprises? The technology is backward and the salary is low. I can't find a job after lying flat for several years
随机推荐
Zero foundation software testing must see, 10 years of testing old bird's conscience suggestions (a total of 15)
.NET 5.0+ 无需依赖第三方 原生实现定时任务
leetcode:111. Minimum depth of binary tree
New situation of digital collection market
Wireshark TS | confusion between fast retransmission and out of sequence
Venv: directory structure of venv
bash: ln: command not found
C# 一行代码计算文件的MD5值 - CodePlus系列
Error: missing revert data in call exception
venv: venv 的目录结构
Rising stars in Plant Sciences (rsps2022) final Science Lecture (6.30 pm)
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
Superscalar processor design yaoyongbin Chapter 4 branch prediction -- Excerpt from subsection 4.1
What if the win11 account is locked and unable to log in? Win11 account is locked and unable to log in
Continue to advance, and softcom power steadily promotes cloud intelligence strategy
[paper reading] trajectory guided control prediction for end to end autonomous driving: a simple yet strong Ba
Does anyone know the logic of limit statement execution in Clickhouse? In the picture, the SQL above can be executed successfully
The Lantern Festival is held on the fifteenth day of the first month, and the Lantern Festival begins to celebrate the reunion
Sqlization is the first step in ETL incremental production. What are the core capabilities of such an architecture?
[dark horse morning post] Yu Minhong said he never looked at the stock price of New Oriental; Hengchi 5 will start pre-sale in July; Naixue virtual stock or suspected of illegal fund-raising; From Jul