日期:2014-05-16  浏览次数:20515 次

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;

-----------------------------下面是自已建的测试表----------------------------
/*create table STUBASEINFO(ID NUMBER(10)
       CONSTRAINT STUBINFO_id_pk PRIMARY KEY,
       STUID NUMBER(8) NOT NULL UNIQUE,
       STUNAME VARCHAR2(20) NOT NULL,
       SEX NUMBER DEFAULT 1 NOT NULL,
       PHONE VARCHAR2(13),
       MOBILE VARCHAR2(11),
       ADDR VARCHAR2(100),
       EMAIL VARCHAR(100),
       FLAG NUMBER DEFAULT 1 NOT NULL,
       OPRTIME DATE DEFAULT SYSDATE
       );
       comment on column STUBASEINFO.STUID is '学号与学生履历表中的学号一对一';
       comment on column STUBASEINFO.FLAG is '学生的状态信息' */
       
       
   /*    create table STURESUME(ID NUMBER(10) CONSTRAINT STURESUME_id_pk PRIMARY KEY,
                              STUID NUMBER(8) NOT NULL UNIQUE,
                              EXPERIENCEONE VARCHAR2(200),
                              EXPERIENCETWO VARCHAR2(200),
                              EXPERIENCETH VARCHAR2(200),
                              EXPERIENCEFOUR VARCHAR2(200),
                              EXPERIENCEFIVE VARCHAR2(200),
                              OPRTIME DATE DEFAULT SYSDATE);
                              COMMENT ON TABLE STURESUME IS '学生履历记录表';
                              COMMENT ON COLUMN STURESUME.STUID IS '学号与stubaseinfo表中一对一关系';
                              COMMENT ON COLUMN STURESUME.EXPERIENCEONE IS '第一个工作经验或是取得的成就';
                              COMMENT ON COLUMN STURESUME.OPRTIME IS '操作时间'; */

---给两表增加序列
--CREATE SEQUENCE STUBASEINFO_ID increment by 1;
--CREATE SEQUENCE STURESUME_ID increment by 1;


---给两表新增一条数据信息(测试)
INSERT INTO STUBASEINFO(ID,STUID,STUNAME,SEX,MOBILE,ADDR) Values(STUBASEINFO_ID.nextval,'01080001','赵敏敏',0,'13912345678','杭州市西湖区');

INSERT INTO STURESUME(ID,STUID,EXPERIENCEONE,EXPERIENCETWO) VALUES(STURESUME_ID.NEXTVAL,'01080001','取得数据库工程师证','学生管理系统开发');