您的位置:首页 > 数据库 > Oracle

oracle 创建表空间、表、主键、外键、序列

2012-09-07 14:51 369 查看
--创建表空间
create tablespace projects
datafile 'D:\projects.dbf'
size 10m autoextend on;
--创建用户名
create user proj
identified by proj
default tablespace projects;
--分配系统权限和角色
grant connect to proj;
--创键表和其它对象
grant resource to proj;
grant dba to proj;
--连接该用户
connect proj/proj;
--创建序列
create sequence U_seq
minvalue 1
maxvalue 10000
start with 1
increment by 1
cache 20;
--创建表
create table Users

Id varchar2(10) not null primary key,
uName varchar2(20) not null,
uPwd varchar2(10) not null,
uSex varchar2(10) not null,
uEmail varchar2(20) not null,
uLike varchar2(20)
);
--为表插入数据
insert into Users values(U_seq.nextval,'aa','123456','女','feiyan811@126.com','唱歌');
insert into Users values(U_seq.nextval,'bb','123456','男','feiyan811@126.com','篮球');
create sequence U_order
minvalue 1
maxvalue 10000
start with 1
increment by 1
cache 20;
--创建表
create table Orders
(
id varchar(2) not null primary key,
uuid varchar2(10) not null,
oName varchar2(20) not null,
oPrice number not null,
oNum number not null
);
--创建主外键关系
alter table Orders add constraint fk_Id foreign key (uuid) references Users(id);
--创建约束
alter table Users add constraint ck_Upwd check(length(Upwd)=6);
插入数据
insert into Orders values(U_order.nextval,'1','oracle书籍',98.88,1);
insert into Orders values(U_order.nextval,'2','java书籍',128.88,1);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle cache java