Oracle数据库建表、序列、索引
发布时间:2020-12-12 15:30:02 所属栏目:百科 来源:网络整理
导读:一、创建序列 -- 创建序列号(如果存在则先删除再创建)declare num number; begin select count(0) into num from user_sequences where sequence_name ='SEQ_USER_ID'; if num0 then execute immediate 'drop sequence SEQ_USER_ID'; end if; end; /create
一、创建序列-- 创建序列号(如果存在则先删除再创建)
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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
