1、创建表
create table Student(
Sno char(9) primary key,
Sname char(20),
Ssex char(2),
Sage smallint,
Sdept char(20)
);
create table Course(
Cno char(4) primary key,
Cname char(40),
Cpno char(4),
Ccredit smallint,
foreign key (Cpno) references Course(Cno)
);
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)
);
2、修改基本表
1)在Student表中加入属性BloodType(char(2)型)。
alter table Student add BloodType char(2);
2)修改表student中的Sdept属性的数据类型为varchar2(40),注意和定义表的时候类型不同。
alter table Student modify (Sdept varchar2(40));
3)给表student的sage列添加一个自定义约束sage必须大于15且小于30。
alter table Student add check (Sage>15 and Sage<30);
4)删除3)中新添加的约束。
select * from user_constraints where table_name='STUDENT';
alter table Student drop constraint SYS_C0011317;

这篇博客详细介绍了数据库的基本操作,包括创建表(如Student、Course、SC),修改表结构(如添加、修改、删除字段及约束),删除表,以及索引的创建与删除。此外,还涉及了数据的插入、更新和删除操作,以及一些数据库管理的思考问题,如外键约束和表删除策略。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



