数据库实验报告学习

数据库实验报告学习

01 数据库及数据表的创建与删除 

02 SQL语言

03 SQL查询数据

04 用户权限管理

05 Oracle数据库对象

06 数据备份与恢复

07数据库系统设计综合实验

实验报告要插入的表

--学生表
drop table sc;
drop table student;
drop table course;

create table Student
(
  Sno char(9) primary key,/*列级完整性约束条件*/
  Sname char(20) unique,
  Ssex char(3), 
  Sage smallint, 
  Sdept char(20)
);
insert into Student(sname,ssex,sno, sage, sdept) values('李勇','男','201215121',20,'CS');
insert into Student(sname,ssex,sno, sage, sdept) values('刘晨','女','201215122',19,'CS');
insert into Student(sname,ssex,sno, sage, sdept) values('王敏','女','201215123',18,'MA');
insert into Student(sname,ssex,sno, sage, sdept) values('张立','男','201215125',19,'IS');

--select * from student;
create table Course
(
  Cno char(4) primary key,
  Cname char(40),
  Cpno char(4),
  Ccredit smallint,
  foreign key (Cpno)  references Course(Cno)/*表级完整性约束条件*/
);
--select * from course order by cno;
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);


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)  
);

insert into sc values('201215121','1',92);
insert into sc values('201215121','2',85);
insert into sc values('201215121','3',88);
insert into sc values('201215122','2',90);
insert into sc values('201215122','3',80);

insert into student values ('1','1','1',1,1);
alter table student add pwd varchar2(20) default '123456';
select *from student;
select *from course;
select *from sc;
select index_name from user_indexes where table_name = 'course';
select view_name from user_views;
commit;

--项目信息管理数据库DDL
alter table Department drop constraint fk_department_manage_teacher;
alter table MyProject drop constraint fk_myproject_pp_myproject;
alter table MyProject drop constraint fk_myproject_projectma_teacher;
alter table TM drop constraint fk_tm_tm_teacher;
alter table TM drop constraint fk_tm_tm2_myproject;
alter table Teacher drop constraint fk_teacher_belongto_department;
drop table Department cascade constraints;
drop table MyProject cascade constraints;
drop table TM cascade constraints;
drop table Tearcher cascade constraints;

create table Department
(
    Dno varchar2(10) not null,
    Tno varchar2(20),
    Dname nvarchar2(20) not null,
    constraint pk_department primary key (Dno)
  );
  select *from Department;
  create table Myproject
  (   
      Pno varchar2(20) not null,
      Parentpno varchar2(20),
      Tno varchar2(20) not null,
      Pname nvarchar2(30) not null,
      Pfund number(20,2),
      Pbegindate date not null,
      Ptimespan integer not null,
      constraint pk_myproject primary key(pno)
  );
  select *from Myproject;
  create table Tm
  (
      Tno varchar2(20) not null,
      Pno varchar2(10) not null,
      WorkDays integer ,
      constraint pk_tm primary key(Tno,Pno)
  );
  select *from Tm;
  create table Teacher
  (
     Tno varchar2(20) not null,
     Dno varchar2(10) not null,
     Tname nvarchar2(20) not null,
     Tsex varchar2(3) not null,
     Tsalary number(30,2), 
     Tbirthday date not null,
     constraint pk_teacher primary key(Tno)
  );
  select *from Teacher;
  alter table Department add constraint fk_department_manage_teacher  foreign key(Tno) references Teacher(Tno);
  alter table Myproject add constraint fk_myproject_pp_myproject  foreign key(Parentpno) references Myproject(Pno);
  alter table Myproject add constraint fk_myproject_projectma_teacher  foreign key(Tno) references Teacher(Tno);
  alter table TM add constraint fk_tm_tm_teacher  foreign key(Tno) references Teacher(Tno);
  alter table TM add constraint fk_tm_tm2_myproject  foreign key(Pno) references Myproject(Pno);
  alter table Teacher add constraint fk_teacher_belongto_department  foreign key(Dno) references Department(Dno);
  
  insert into department(dno,dname) values('d001','计算机科学系');
  insert into department(dno,dname) values('d002','网络工程系');
  insert into department(dno,dname) values('d003','软件工程系');
  select *from department;
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t001','张三','男',3000,To_date('7-7月-1977','DD-mon-yyyy'),'d001');
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t002','李四','女',3600,To_date('21-10月-1979','DD-mon-yyyy'),'d001');
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t003','王五','女',5600,To_date('7-7月-1981','DD-mon-yyyy'),'d002');
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t004','刘晨','女',5800,To_date('7-7月-1985','DD-mon-yyyy'),'d002');
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t005','王小二','男',3500,To_date('7-7月-1981','DD-mon-yyyy'),'d003');
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t006','李小龙','男',5687,To_date('7-12月-1990','DD-mon-yyyy'),'d003');
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t007','熊猫','男',6000,To_date('27-11月-1980','DD-mon-yyyy'),'d003');
  insert into teacher(tno,tname,tsex,tsalary,tbirthday,dno) values('t008','李小小','女',5687,To_date('17-10月-1980','DD-mon-yyyy'),'d001');
  select *from teacher;
  --myproject 数据
  insert into myproject(Pno,Pname,Pfund,Pbegindate,ptimespan,parentpno,tno) values ('p0001','信息安全技术研究',30,TO_date('7-12月-2012','DD-mon-yyyy'),3,null,'t001');
  insert into myproject(Pno,Pname,Pfund,Pbegindate,ptimespan,parentpno,tno) values ('p0002','云计算研究',40,TO_date('7-12月-2008','DD-mon-yyyy'),4,null,'t003');
  insert into myproject(Pno,Pname,Pfund,Pbegindate,ptimespan,parentpno,tno) values ('p0003','信息中心网络研究',30,TO_date('7-12月-2012','DD-mon-yyyy'),6,null,'t006');
  insert into myproject(Pno,Pname,Pfund,Pbegindate,ptimespan,parentpno,tno) values ('p0004','对等网络研究',30,TO_date('7-12月-2010','DD-mon-yyyy'),3,null,'t006');
  select *from myproject;
  --tm 数据
  insert into tm(tno,pno,workdays) values('t001','p0001',180);
  insert into tm(tno,pno,workdays) values('t001','p0002',180);
  insert into tm(tno,pno,workdays) values('t001','p0004',360);
  insert into tm(tno,pno,workdays) values('t001','p0003',540);
  insert into tm(tno,pno,workdays) values('t002','p0001',720);
  insert into tm(tno,pno,workdays) values('t002','p0002',90);
  insert into tm(tno,pno,workdays) values('t002','p0004',90);
  insert into tm(tno,pno,workdays) values('t003','p0001',180);
  insert into tm(tno,pno,workdays) values('t003','p0002',360);
  insert into tm(tno,pno,workdays) values('t003','p0003',360);
  insert into tm(tno,pno,workdays) values('t003','p0004',360);
  insert into tm(tno,pno,workdays) values('t004','p0001',180);
  insert into tm(tno,pno,workdays) values('t004','p0002',180);
  insert into tm(tno,pno,workdays) values('t003','p0003',360);
  insert into tm(tno,pno,workdays) values('t005','p0004',180);
  insert into tm(tno,pno,workdays) values('t005','p0002',720);
  insert into tm(tno,pno,workdays) values('t006','p0004',360);
  insert into tm(tno,pno,workdays) values('t006','p0002',180);
  insert into tm(tno,pno,workdays) values('t006','p0003',720);
  select *from tm;
  update department set tno='t006'where tno='d003';
  commit;
 

你可能感兴趣的:(数据库学习)