Oracle,sqlserver,mysql的自增变量设置
2009-02-21 21:05
337 查看
Oracle,sqlserver,mysql的自增变量设置
不同的东家养不同的女儿,这三种数据库在设置自增变量方面都是不同的,下面我归类了一下:
1、Mysql。它的自增变量个人有认为是最好记的,使用AUTO_INCREMENT关键字,知道英文的就更好记忆了,如下创建一个带有自增变理的表:
Sql代码
create table test(id int AUTO_INCREMENT primary key not null,name varchar(50));
注:这里的id一定要申明为主键,否则会引来报错。
2、Sqlserver使用identity关键字,可以很容易指定从什么数开始,增幅是多少,如下:
Sql代码
create table test(id int identity(100,10) primary key not null,name varchar(50));
3、Oracle不能够在创建表的时候指定自动关键字,它需要重新创建sequence,然后以"创建键.nextval"来引用:
Sql代码
create table test(id int primary key not null,name varchar(50));
create sequence test_id(最好是表名+序列号标记) increment by 1 start with 1 maxvalue 9999;
引用的时候就要这样引用了,如下:
Sql代码
insert into test(test_id.nextval,'www');
不同的东家养不同的女儿,这三种数据库在设置自增变量方面都是不同的,下面我归类了一下:
1、Mysql。它的自增变量个人有认为是最好记的,使用AUTO_INCREMENT关键字,知道英文的就更好记忆了,如下创建一个带有自增变理的表:
Sql代码
create table test(id int AUTO_INCREMENT primary key not null,name varchar(50));
create table test(id int AUTO_INCREMENT primary key not null,name varchar(50));
注:这里的id一定要申明为主键,否则会引来报错。
2、Sqlserver使用identity关键字,可以很容易指定从什么数开始,增幅是多少,如下:
Sql代码
create table test(id int identity(100,10) primary key not null,name varchar(50));
create table test(id int identity(100,10) primary key not null,name varchar(50));
3、Oracle不能够在创建表的时候指定自动关键字,它需要重新创建sequence,然后以"创建键.nextval"来引用:
Sql代码
create table test(id int primary key not null,name varchar(50));
create sequence test_id(最好是表名+序列号标记) increment by 1 start with 1 maxvalue 9999;
create table test(id int primary key not null,name varchar(50)); create sequence test_id(最好是表名+序列号标记) increment by 1 start with 1 maxvalue 9999;
引用的时候就要这样引用了,如下:
Sql代码
insert into test(test_id.nextval,'www');
相关文章推荐
- Oracle,sqlserver,mysql的自增变量设置
- Oracle,sqlserver,mysql的自增变量设置
- Oracle,sqlserver,mysql的自增变量设置
- Oracle,SQL,MySQL的自增变量设置
- 数据库-Oracle【Oracle数据库设置默认表空间问题及Oracle,SQL,MySQL的自增变量设置】
- Oracle,SQL Server,MySQL的自增变量设置
- Oracle,SQL Server,MySQL的自增变量设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- 深入Mysql,SqlServer,Oracle主键自动增长的设置详解
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- Oracle, Mysql,SqlServer主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- oracle ,mysql,sqlserver 字段设置默认值是否为空测试
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- Mysql,SqlServer,Oracle主键自动增长的设置
- 深入Mysql,SqlServer,Oracle主键自动增长的设置详解