1)为用户wang定义一个学生-课程模式S-T
create schema "S-T" authorization wang;
2)为用户wang定义一个模式wang
create schema authorization wang;
格式:create schema 模式名 authorization 用户名;,若未指明模式名,则模式名隐含为用户名,创建之前必须获得权限
3)为用户zhang创建一个模式test,并定义一个表tab1
create schema test athorization zhang
create table tab1
(
col1 numeric(10,3), //10位数字,其中3位小数
col2 decimal(5,20 //同numeric
);
4)删除模式zhang,同时该模式下定义的tab1也被删除
drop schema zhang cascade;
cascade 是将模式中的所有对象删除,restrict 是模式中没有任何对象时才执行删除模式
5)建立学生表Student
create table
(
Sno char(9) primary key,
Sname char(20) unique,
Ssex char(2),
Sage smallint,
Sdept char(20)
); //Sno是主码,Sname有唯一性约束
6)建立课程表Course
create table Course
(
Cno char(9) primary key,
Sname char(40) not null,
Cpno char(4),
Credit smallint,
foreign key(Cpno) references Course(Cno)
); //Cpno是外码,被参照表Course,被参照列Cno
7)建立学生选课表SC