[转 逆水行船]Oracle中成立表,创制体系,创造自增字段,添加注释, 添加记录,添加触发器,提交

貌似人习惯了其他数据库的操作,有2个字段是自增连串的字段,可是查询了oracle的连带扶持,没有该设置.

翻开了相关的篇章,转发那篇小说给大家大饱眼福

 

// 创造一个行列
CREATE SEQUENCE Car_GUID increment by 1;

// 创造一个表
CREATE TABLE Car
(
 GUID NUMBER NOT NULL PRIMARY KEY,
 PhoneId Char(11) NOT NULL,
 UserName VarChar(20) NOT NULL
);

// 添加注释
comment on table car is ‘定位音讯用户表’;
Comment on column car.guid is ‘自增字段’;
Comment on column Car.PhoneId is ‘电话唯一标识’;
Comment on column Car.UserName is ‘用户名称’;

// 添加一条记下
INSERT INTO Car(GUID, PhoneId, UserName) Values(CAR_GUID.nextval,
‘13589256783’, ‘张三’);

// 提交
commit;

// 触发器
create or replace trigger Trigger_Car_GUID_Insert 
before insert on Car
for each row
begin
 select CARGUIDSEQ.nextval into  :new.GUID from sys.dual;
end;

相关文章