ORACLE创建id自增的表,及相关语句

新建下载权限记录表   DOWNLOADPOPE_TAB 

字段:id、用户id、有下载权限的下载中心分类表id、有上传权限的下载中心分类表id

ID(int)、userid(int)、downid(string)、upid(string)

执行语句
//1创建
CREATE TABLE DOWNLOADPOPE_TAB
(
    ID  INT NOT NULL,
    USERID  INT NOT NULL,
    DOWNID  VARCHAR(60),
    UPID VARCHAR(60),
    CONSTRAINT DOWNLOADPOPE_TAB PRIMARY KEY (ID)
);
//2创建自动增长序列
CREATE SEQUENCE DOWNLOADPOPE_TAB_Sequence
INCREMENT BY 1   
START WITH 1  
NOMAXVALUE      
NOCYCLE
CACHE 10;
//3创建触发器
CREATE TRIGGER DOWNLOADPOPE_TAB BEFORE
insert ON  DOWNLOADPOPE_TAB FOR EACH ROW
begin
select DOWNLOADPOPE_TAB_Sequence.nextval into:New.id from dual;

end;
//4.提交
commit;
//5.插入
INSERT INTO DOWNLOADPOPE_TAB(userid,downid,upid)VALUES(100123,'oracle sql','54.70');
//6.查询
select * from jxpost.DOWNLOADPOPE_TAB
//7.删除数据
DELETE DOWNLOADPOPE_TAB where id=1
//8.删除表
DROP TABLE  DOWNLOADPOPE_TAB

你可能感兴趣的:(oracle,sql,cache)