数据库第一次记录

来源:互联网 发布:算法设计和分析 编辑:程序博客网 时间:2024/06/06 13:21
(一)数据定义
一:
1.1
create table student 
(sno varchar(9) primary key,
sname varchar(20),
ssex varchar(2),
sage int,
sdept varchar(20));


1.2
create table Course
(cno varchar(4) primary key,
cname varchar(40) not null ,
cpno varchar(4),
ccredit smallint,
foreign key(cpno) references Course (cno)
);


1.3 
create table SC
(   Sno varchar(9),
    Cno varchar(4),
    Grade int,
    primary key(Sno,Cno),
    foreign key(Sno)references Student(Sno),
    foreign key(Cno)references Course(Cno)
 );




2.1
alter table student add bloodtype char(2);


2.2
alter table student  modify sdept varchar2(40);


2.3
alter table student add constraint student_sage_chk check (sage between 16 and 29);


2.4
alter table student drop constraint student_sage_chk;


2.5
alter table student drop column bloodtype  ;




3.1
Drop Table Student Cascade Constraints; 


3.2
Drop Table Sc Cascade Constraints; 




二:
1.1
CREATE UNIQUE INDEX stusnam_4068 ON student(Sname);
1.2
CREATE UNIQUE INDEX sc_4068 ON SC(Sno ASC,Cno DESC);


2.1
drop index stusnam_4068;
2.2
drop index sc_4068;
(二)数据操作
一:
1.1
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');
1.2
insert into COURSE values('6','数据处理',null,2);
insert into COURSE values('2','数学',null,2);
insert into COURSE values('4','操作系统','6',3);
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);
1.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','4',90);
insert into SC values('200215122','3',80);


2.1
update Student set Sage=20 where sname='王敏';
2.2
update Student set Sage=Sage+1;
2.3
update sc
set grade=0
where sno in
(select sno from STUDENT where sdept='CS');
3.1
delete from student where sdept=
(select sdept from Student where sname='刘晨');
3.2
先添加cs两条记录
delete from sc where sno in
(select sno from student where sdept='CS');
原创粉丝点击