
实验一 数据定义和数据更新
When defining foreign keys, always enable cascading operations to avoid orphaned records. Use Name constraints descriptively for better readability. Enter SQL commands using English input methods, including spaces and symbols. Ensure schema changes are committed after testing to avoid errors.
发布日期:2021-05-10 01:18:21
浏览次数:16
分类:精选文章
本文共 4467 字,大约阅读时间需要 14 分钟。
Experimental Report on Database Operations
Experiment 1: Data Definition and Data Update
1.1 Experiment Name
Data Definition and Data Update
1.2 Experiment Number
1.1.1
1.3 Experiment Unit
Computing Science and Technology Class of 2016
2.1 Purpose of the Experiment
- Familiarize oneself with database interactive SQL tools.
- Apply SQL language to define and modify basic tables and indexes.
- Update data in tables through specific commands.
2.2 Experimental Environment
- Software: Oracle 11g, SQL Developer
- Operating System: Windows 7
- Environment: Local development environment
2.3 Experimental Content and Results
2.3.1 Basic Table Operations
Table Creation
- Student Table:
Student(Sno, Sname, Ssex, Sage, Sdept)
create table Student( Sno char(9) primary key, Sname char(20), Ssex char(2), Sage smallint, Sdept char(20));
- Course Table:
Course(Cno, Cname, Cpno, Ccredit)
create table Course( Cno char(4) primary key, Cname char(40), Cpno char(4), Ccredit smallint, foreign key (Cpno) references Course(Cno));
- Student Enrollment Table:
SC(Sno, Cno, Grade)
create table SC( Sno char(9), Cno char(4), Grade smallint, primary key (Sno, Cno), foreign key (Sno) references Student(Sno), foreign key (Cno) references Course(Cno));
Table Modification
- Add Blood Type to Student Table
alter table Student add BloodType char(2);
- Modify Department Column Type
alter table Student modify (Sdept varchar2(40));
- Add Custom Constraint to Age Column
alter table Student add check (Sage > 15 and Sage < 30);
- Remove Constraint
alter table Student drop constraint CK_STUDENT;
- Remove Blood Type Column
alter table Student drop BloodType;
Table Deletion
- Delete Student Table with Constraints
drop table Student cascade CONSTRAINTS;
- Delete Student Enrollment Table and Its Constraints
drop table SC cascade CONSTRAINTS;
2.3.2 Index Operations
Index Creation
- Create Unique Index on Student Name in Student Table
create unique index stusnam on Student(Sname);
- Create Composite Index on Student Enrollment Table
create unique index i_sc on SC(Sno asc, Cno desc);
Index Deletion
- Remove Indexes from Student and Course Tables
drop index stusnam;
drop index i_sc;
2.3.3 Data Operations
Data Insertion
- Insert Data into Student Table
insert into Student values('200215121', '李勇', '男', '20', 'CS');insert into Student values('200215122', '刘晨', '女', '19', 'CS');insert into Student values('200215123', '王敏', '女', '18', 'MA');insert into Student values('200215125', '张立', '男', '19', 'IS');
- Insert Course Data
insert into Course values('2', '数字', null, '2');insert into Course values('6', '数据处理', null, '2');insert into Course values('7', 'PASCAL语言', '6', '4');insert into Course values('4', '操作系统', '6', '3');insert into Course values('5', '数据结构', '7', '4');insert into Course values('1', '数据库', '5', '4');insert into Course values('3', '信息系统', '1', '4');
- Insert Student Enrollment Data
insert into SC values('200215121', '1', '92');insert into SC values('200215121', '2', '85');insert into SC values('200215121', '3', '88');insert into SC values('200215122', '4', '90');insert into SC values('200215122', '3', '80');
Data Update
- Update Age of Wang Mei
update Student set Sage = 20 where Sname = '王敏';
- Increment Age of All Students
update Student set Sage = Sage + 1;
- Reset Grades for CS Department Students
update SC set Grade = '0' where Sno in( select Sno from Student where Sdept = 'CS');
Data Deletion
- Delete Information for Liu Chen and Related Students
delete from Student where Sdept in( select Sdept from Student where Sname = '刘晨');
- Delete CS Department Enrollment Data
delete from SC where Sno in( select Sno from Student where Sdept = 'CS');
3.1 Considerations
varchar2
for columns expecting variable lengths to minimize issues.4.1 Discussion Questions
Implementing Foreign Key Constraints
alter table table_name add constraint FK foreign key (column_name) references referenced_column;
Deleting a Table with Foreign Keys
- Enable cascading deletion before dropping the table.
Modifying Column Data Types
- Columns must be empty or have NULL values to modify or drop constraints.
5. Advisor's Comments
#_end#
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2025年04月09日 02时48分04秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Linux小操作LVM
2019-03-07
Split返回数组元素含有空字符串移除
2019-03-07
解决VS中C语言运行scanf错误
2019-03-07
Java注解
2019-03-07
idea上的程序报错-> 错误: 找不到或无法加载主类
2019-03-07
java--07整数反转
2019-03-07
SQLServer 安装提示需要重启计算机的解决方案
2019-03-07
java刷题--49字母异位词分组
2019-03-07
《web安全入门》(四)前端开发基础Javascript
2019-03-07
laravel中视图模板的表单提交
2019-03-07
在Ubuntu上检查一个软件包是否安装命令
2019-03-07
Walle-瓦力上线部署安装以及遇到的问题
2019-03-07
mysql的group by ,order by语句的使用
2019-03-07
call_user_func函数和call_user_func_array函数
2019-03-07
配置php.ini文件,关闭错误提示,打开错误日志,设置错误日志路径
2019-03-07
接收get或post数据使用fwrite写入文件中,方便追踪错误;或其他几种缓存方式
2019-03-07
mysql开启慢查询日志及查询
2019-03-07
vuex最简单、最详细的入门文档
2019-03-07
glog配置与持久化记录
2019-03-07
Window平台Grpc框架搭建
2019-03-07