Oracle中建表和指定表空间

--建一个表
create table HH2(

tid number primary key ,--主键设定

tname varchar2(20)

);

--删除表
drop table HH;

 

--表空间(相当于一个数据库)(DBA权限)
create tablespace test
datafile 'D:test.dbf'
size 10M
autoextend on
next 10M
maxsize 100M

--指定表在那个表空间里面(默认在USERS表空间里)
create table HH(tid number primary key)
tablespace test;
select * from tabs;

--删除 表空间
drop tablespace test including contents and datafiles --连带物理文件和表空间中的数据也一起删除

 

 

--建表建约束
create table student1(
sid number primary key ,
sname varchar2(20) not null,
sage number,
ssex char(2),
saddress varchar2(100),
cid number references tclass(cid)--建立外键关系
);

create table tclass
(
cid number primary key,
cname varchar2(20)
);
--唯一unique 检查 check 默认值 modify 添加外键关系 添加列
alter table student1 add constraint UQ_student1_sname unique(sname);
alter table student1 add constraint CK_student1_agae check(sage between 19 and 70);
alter table student1 modify ssex default '男';
alter table student1 add constraint FK_student1_cid foreign key(cid) references tclass(cid);
alter table student1 add dt date;
--删除约束
alter table student1 drop constraint UQ_student1_sname ;

 

posted @ 2014-04-13 23:24  莫名字  阅读(24292)  评论(1编辑  收藏  举报