oracle运用(二) oracle数据库完整建表语句

本文介绍如何使用SQL语句判断并操作数据库中的物流建议表,包括检查表是否存在并删除,以及创建表结构的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--判断表是否存在,如果存在则删除
declare 
      num   number; 
begin 
      select count(1) into num from all_tables where TABLE_NAME = 'LOGISTICS_SUGGESTION';      --  and OWNER='SCOTT'
      if   num=1   then 
          execute immediate 'drop table LOGISTICS_SUGGESTION'; 
      end   if; 
end; 


-- Create table  
   
CREATE TABLE LOGISTICS_SUGGESTION
(
  id            	NUMBER not null,
  industry_id     	NUMBER,
  contact_name   	VARCHAR2(128),
  contact_phone   	VARCHAR2(128),
  handle_status		VARCHAR2(32),
  suggestion_remark VARCHAR2(500),
  handle_remark 	VARCHAR2(500),
  create_time   	DATE default sysdate,
  handle_time   	DATE
); 
  
--指定表空间(可以不指定)  
tablespace DSW  
  pctfree 10  
  pctused 40  
  initrans 1  
  maxtrans 255  
  storage  
  (  
    initial 64K  
    minextents 1  
    maxextents unlimited  
  );  
    
-- Add comments to the table   
comment on table LOGISTICS_SUGGESTION is '投诉建议表'; 
 
-- Add comments to the columns   
comment on column LOGISTICS_SUGGESTION.id is '自增,主键';
comment on column LOGISTICS_SUGGESTION.industry_id is '行业类别';
comment on column LOGISTICS_SUGGESTION.contact_name is '联系人';
comment on column LOGISTICS_SUGGESTION.contact_phone is '联系方式';
comment on column LOGISTICS_SUGGESTION.handle_status is '处理状态(处理中WORKING、已处理FINISH)';
comment on column LOGISTICS_SUGGESTION.suggestion_remark is '投诉建议';
comment on column LOGISTICS_SUGGESTION.handle_remark is '处理备注';
comment on column LOGISTICS_SUGGESTION.create_time is '创建时间';
comment on column LOGISTICS_SUGGESTION.handle_time is '处理时间'; 
  
-- Create/Recreate primary, unique and foreign key constraints   
alter table LOGISTICS_SUGGESTION  
  add constraint PK_LOGISTICS_SUGGESTION primary key (ID)  
  using index   
  tablespace SYSTEM  
  pctfree 10  
  initrans 2  
  maxtrans 255  
  storage  
  (  
    initial 64K  
    minextents 1  
    maxextents unlimited  
  );  
    
-- Create sequence   
create sequence LOGISTICS_SUGGESTION_SEQ  
minvalue 1    -- 最小值=1  
maxvalue 999999999999999999999999999  -- 指定最大值   
-- 或nomaxvalue      -- 没有最大值  
-- NOCYCLE;      -- 不循环  
start with 1   -- 从1开始  
increment by 1  -- 每次递增1  
cache 20;  
  
--触发器  
create or replace trigger LOGISTICS_SUGGESTION_TRI  
  before insert on LOGISTICS_SUGGESTION    
REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW  
begin  
    SELECT LOGISTICS_SUGGESTION_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;  
end;  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值