一.模式的定义与删除
1.创建一个用户
设置用户名然后登陆名选择第一个
2.模式的定义
要创建模式,必须拥有数据库管理员权限,或者获得了数据库管理员赋予的create schema的权限
先查看是不是在自己想要的数据库里面建立模式
然后点击新建查询
输入代码实现在wang用户下建立模式S-T
create schema "S-T" authorization wang;
3.在模式中定义一个表TAB1
在S-T模式下建立一个表tab1
create schema "S-T" authorization wang;
create table TAB1(col1 smallint,
col2 int,
col3 char(20),
col4 numeric(10,3),
col5 decimal(5,2)
);
4.模式的删除
如果模式中有数据库对象不能直接把它删除,应该先删除其中的数据
drop schema "S-T";//当模式中没有数据库对象时
drop table "S-T".TAB1;//先删除数据
drop schema "S-T";
二.基本表的定义,删除与修改
1.建立表
create table Student
(Sno char(9) primary key,
Sname char(20) unique,
Ssex char(2),
Sage smallint,
Sdept char(20)
);
create table Course
(Cno char(4) primary key,
Cname char(40) not null,
Cpno char(4),
Ccredit smallint,
foreign key(Cpon) 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.修改基本表
例3.8
alter table Student add S_entrance date;//增加入学时间列,数据类型为日期型
例3.9
alter table Student alter column Sage int;//将年龄数据类型修改
例3.10
alter table Course add unique(Cname);//给课程名称增加条件必须取唯一值的约束条件
3.删除基本表
drop table 表名;