ORACLE表设置主键自增

--创建表
create table BJ_ZR_LNGWEEKREPORT_GasCompnt(
idNumber number primary key,  --主键、自增长
gasName NVARCHAR2(100) not null,
gasRatio NUMBER(10,2) not null,
salesDate  DATE
);

--创建序列
CREATE SEQUENCE lngGasCompnt_sequence
INCREMENT BY 1   -- 每次加几个
START WITH 100     -- 从1开始计数
NOMAXVALUE        -- 不设置最大值
NOCYCLE               -- 一直累加,不循环
NOCACHE               -- 不建缓冲区

--创建触发器
create trigger lngGasCompnt_trig before
insert on BJ_ZR_LNGWEEKREPORT_GasCompnt for each row when (new.idNumber is null)
begin
         select lngGasCompnt_sequence.nextval into:new.idNumber from dual;
end;

常用表结构操作

--添加表字段
   alter  table  tablename  add(columnName  columnType); 

--删除字段的语法:
   alter  table  tablename  drop(columnName);

--修改字段名
   alter  table tableName rename column oldCName to newCName;

--修改数据类型
   alter  table  tableName  modify(columnName 数据类型);

--删除触发器
   drop  trigger  triggerName;

--删除序列
   drop  sequence  sequenceName;

--修改表名字

扫描二维码关注公众号,回复: 2429447 查看本文章

   alter  table  old_table_name  rename  to  new_table_name;

--修改字段为非空

   alter  table  tableName  modify  columnName  not  null  enable  novalidate;

--修改表字段为空

   alter  table  tableName  modify  columnName  default  null;

猜你喜欢

转载自blog.csdn.net/ysh598923879/article/details/81168565