--建立表
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;
--修改表名字
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;