数据库实验一( 表、视图和索引的管理 )
2017-05-25 21:48
375 查看
建立学生表 create table Student ( Sno char(20) primary key, Sname char(10) not null, Sage int, Ssex char(5), Sdept char(20) ); 建立课程表 create table Course ( Cno char(10) primary key, Cname char(20) not null, Cpno char(10), Ccredit int, foreign key(Cpno)references Course(Cno) ); 建立学生选课表 create table SC ( Sno char(20), Cno char(10), Grade numeric(5,2), foreign key(Sno) references Student(Sno), foreign key(Cno) references Course(Cno) ); 4. 运行下列语句,为基本表添加数据; --以下为学生表的初始数据 insert into Student(sname,ssex,sno, sage, sdept) values('李勇','男','200215121',20,'CS'); insert into Student(sname,ssex,sno, sage, sdept) values('刘晨','女','200215122',19,'CS'); insert into Student(sname,ssex,sno, sage, sdept) values('王敏','女','200215123',18,'MA'); insert into Student(sname,ssex,sno, sage, sdept) values('张立','男','200215125',19,'IS'); --以下为课程表的初始数据 insert into course values('6','数据处理',null,2); insert into course values('2','数学',null,2); insert into course values('7','PASCAL 语言','6',4); insert into course values('5','数据结构','7',4); insert into course values('1','数据库','5',4); insert into course values('3','信息系统','1',4); insert into course values('4','操作系统','6',3); --以下为选修表的初始数据 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','2',90); insert into sc values('2002151 4000 22','3',80); commit; 5. 修改 Student 表,为 Student 表格添加一个“入学时间”属性,属性名为 Senrollment; alter table student add senrollment date; 6. 修改 Student 表,把 Ssex 列的宽度设置为 6 个字节; alter table student modify ssex char(6); 7. 修改 Student 表,删除 Senrollment 列; alter table student drop column senrollment; 8. 创建视图 ds,该视图包含所有选修了“数据库原理”的学生信息; create view ds as select * from student where sno in(select sno from sc where cno in(select cno from course where cname='数据库原理')); 9. 创建视图 malestudent,该视图包含男学生所有信息,通过视图 malestudent 更新基本表数据时必须保证学生性别为男; create view malestudent as select * from student where ssex='男' with check option; 10. 删除视图 malestudent; drop view malestudent; 11. 为 Course 表的 CName 列建立唯一索引,索引名称为 uniqueCname; create unique index uniquecname on course(cname); 12. 试着为 Course 表的 Cpno 列建立唯一索引,索引名为 indexCpno1,如果发生错误, 请说明普通索引和唯一索引有何区别; create unique index indexcpno1 on course(cpno); ORA-01452: 无法 CREATE UNIQUE INDEX; 找到重复的关键字 唯一索引只能对应唯一数据记录. 13. 为 Course 表的 Cpno 列建立普通索引,索引名称为 indexCpno2 create index indexcpno2 on course(cpno); 14. 删除索引 indexCpno2; drop index indexcpno2; 15. 删除基本表 Student,如果发生错误,请分析原因; drop table student; ORA-02449: 表中的唯一/主键被外键引用 因为主键被course引用. 16. 删除基本表 SC; drop table sc;
相关文章推荐
- Greenplum中定义数据库对象之创建与管理序列、索引以及视图
- 数据库实验三 索引与视图
- [网络问题,截图以后再传]本实验是设计性实验。目的在于使用关系数据库标准语言SQL,掌握视图和索引的操作。
- 数据库-视图-索引-触发器
- HubbleDotNet 开源全文搜索数据库项目--为数据库现有表或视图建立全文索引(三) 多表关联全文索引模式
- 转帖杂和数据库------- SQL-server 数据库相关知识 事务、索引、视图
- 第五部分:高级查询 第六部分:常规索引管理 第七部分:全文索引管理 第八部分:数据库的备份和恢复 第九部分:数据库的安全管理
- 数据库实例-学生名册管理系统(DAO的使用实验)
- 修复Domino数据库视图索引的两种方法
- 数据库是否使用外键,及视图,索引,存储过程的一些说明(zz)
- 数据库是否使用外键,及视图,索引,存储过程的一些说明(zz)
- 数据库中创建视图和索引还有存储过程起什么作用?
- 数据库中创建视图和索引还有存储过程起什么作用?
- 创建数据库、表、主外键、各种约束、存储过程、视图、索引、事务使用、触发器、创建登录账号、数据库用户 Sql语句示例
- 使用SQL Server动态管理视图确认缺失索引(转)
- 实验六 教务管理数据库的设计
- MSSQL数据库管理---索引
- SQL2K数据库开发二十二之索引操作在视图上创建索引
- 转帖杂和数据库------- SQL-server 数据库相关知识 事务、索引、视图
- 数据库管理进阶,MySQL索引分析和优化