前端之家收集整理的这篇文章主要介绍了
Oracle数据库建表、序列、索引,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一、创建序列
-- 创建序列号(如果存在则先删除再创建)
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;
-- 创建数据库表(如果存在则先删除再创建)
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 '用户名称';
三、创建索引
-- 增加索引
create unique index index_mobile_phone on MS_USER(mobile_phone);
create index index_user_name on MS_USER(user_name);
原文链接:https://www.f2er.com/oracle/211028.html