id自增mysql和oracle不同的方法

在实现id字段自增的过程中,mysql和oracle是完全不同的

mysql

mysql> create table test (

             aid int not null auto_increment,

             site_id int, cout int, date date,

             primary key (aid) );

not null autp_increment 实现自增

oracle

这个百度经验说的很好
https://jingyan.baidu.com/article/4f7d57127394ba5a201927a3.html

创建

CREATE SEQUENCE SEQ_TEST
INCREMENT BY 1 
START WITH 1 
NOMAXvalue 
NOCYCLE 
NOCACHE;

如果需要看下已经创建的序列

//查看所有序列
select * from user_sequences;
//如果需要查看某个特定的序列,如下:
select * from user_sequences  where  sequence_name like '%T_SELL_BRAND%';
select * from user_sequences  where  sequence_name='SEQ_T_SELL_BRAND';

//注意:序列名区分大小写

现在开始插入数据

insert into tableName(a,b,c)values(SEQ_TEST.nextval,'张三',10);

修改、删除序列

使用 alter 命令进行修改

alter sequence student_id -- 序列名 也可以更改
minvalue 1
maxvalue 99999
start with 1
increment by 1
cycle    -- 到99999后,从头开始
nocache;

注:

1、如果想要改变start的值,必须 drop sequence 再重建一个序列

2、如果想要改变minvalue的值,必须删除序列后再重新建立序列化。不可以修改序列化的minvalue。

使用 drop 命令删除

 drop sequence student_id;

你可能感兴趣的:(Oracle,sql,mysql)