Oracle数据库建表、序列号、索引

2017-01-06 10:08:21来源:oschina作者:月光-云海人点击



#### 一、创建序列号
``` sql
-- 创建序列号(如果存在则先删除再创建)
declare
num number;
begin
select count(0) into num from user_sequences where sequence_name ='SEQ_USER_ID';
if num>0 then
execute immediate 'drop sequence SEQ_USER_ID';
end if;
end;
/
create sequence SEQ_USER_ID
minvalue 1
maxvalue 99999999999
start with 1
increment by 1;
```
#### 二、创建数据库表
``` sql
-- 创建数据库表(如果存在则先删除再创建)
declare
num number;
begin
select count(0) into num from all_tables where TABLE_NAME='MS_USER';
if num>0 then
execute immediate 'drop table MS_USER';
end if;
end;
/
create table MS_USER(
user_id number(11) not null primary key,
mobile_phone varchar2(16) not null,
user_name varchar2(32) not null
);
-- 增加数据库表备注和表字段的备注信息
comment on table MS_USER is '用户信息表';
comment on column MS_USER.user_id is '用户ID';
comment on column MS_USER.mobile_phone is '手机号码';
comment on column MS_USER.user_name is '用户名称';
```
#### 三、创建索引
``` SQL
-- 增加索引
create unique index index_mobile_phone on MS_USER(mobile_phone);
create index index_user_name on MS_USER(user_name);
```

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台