由于公司项目需要,建立以下表及其相关,写此博客,作为学习。
文章参考网上其他资料,如有错误,接受指正,共同进步。
-- 新建表空间 TS_ZW_DXPT_DATA
create tablespace TS_WZ_PTDX_DATA
datafile 'ts_wz_ptdx_data_001'
size 10M
autoextend on next 10M;
其中 datafile:数据文件名、size:大小、autoextend:自动增长大小
-- 新建用户 zw_dxpt 默认表空间 TS_WZ_PTDX_DATA
create user wz_ptdx identified by "passw0rd"
default tablespace TS_WZ_PTDX_DATA;
-- 用户授权
grant create view to wz_ptdx;
--连接数据库,资源的权限grant connect,resource to wz_ptdx;
--无限表空间的权限
grant unlimited tablespace to wz_ptdx;
--会话权限
grant create session to wz_ptdx;
--wz_ptdx下创建ptdx_submitmsg表
--number类型长度最大为38,number相较于int在Oracle中更为正式,number的第二位不加限制不能保证为一个整数。
create table wz_ptdx.ptdx_submitmsg(
id number(20,0) not null,
from_user varchar2(50) not null,
check_user varchar2(50) not null,
to_user varchar2(50) not null,
receive_group number(10,0),
msg_title varchar2(100) not null,
msg_text varchar2(255) not null,
msg_length number(38,0),
msg_type number(10,0),
msg_status number(10,0),
create_time date default sysdate,
constraint pk_id1 primary key(id)
)
--ptdx_submitmsg添加注释
--添加表注释:
comment on table wz_ptdx.ptdx_submitmsg IS '提交短信信息表';
--添加字段注释:
comment on column wz_ptdx.ptdx_submitmsg.id is 'id 主键';
comment on column wz_ptdx.ptdx_submitmsg.from_user is '短信发送者';
comment on column wz_ptdx.ptdx_submitmsg.check_user is '短信审核者';
comment on column wz_ptdx.ptdx_submitmsg.to_user is '短信接收者';
comment on column wz_ptdx.ptdx_submitmsg.receive_group is '短信接受对象';
comment on column wz_ptdx.ptdx_submitmsg.msg_title is '短信主题';
comment on column wz_ptdx.ptdx_submitmsg.msg_text is '短信内容';
comment on column wz_ptdx.ptdx_submitmsg.msg_length is '短信长度';
comment on column wz_ptdx.ptdx_submitmsg.msg_type is '短信类型';
comment on column wz_ptdx.ptdx_submitmsg.msg_status is '短信状态';
comment on column wz_ptdx.ptdx_submitmsg.create_time is '短信创建时间';
-- 创建索引
--Oracle建表时会根据主键创建同名索引,无需再次创建索引
-- create index index_ptdx_submitmsg on wz_ptdx.ptdx_submitmsg(id);
minvalue 1
maxvalue 999999999
start with 1
increment by 1
cache 20;
create or replace trigger ptdx_submitmsg_tri
before insert on wz_ptdx.ptwz_submitmsg
for each row
begin
select ptdx_submitmsg_seq.nextval into :new.id from dual;
end;
-- Test insert