mysql 约束条件 auto_increment 自动增长起始值 布长 起始偏移量
我们指定一个字段为自动增长,他默认从1开始自动增长,默认值为1,每次增长为1,步长为1
模糊查询 like
% 代表任意个数字符 任意字符长度
查看mysql正在使用变量
show variables like “auto_inc%”
mysql> show variables like "auto_inc%" ;
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
+--------------------------+-------+
2 rows in set (0.00 sec)
布长
auto_increment_increment 1 起始偏移量
auto_increment_offset 1 # 设置布长
session 是每次登陆产生一个连接 只在本次连接生效 退出了mysql就恢复原状 其他连接都看不到
基于会话级别
set session auto_increment_increment=5; 设置全局的布长
set global auto_increment_increment=5; # 设置起始偏移量 注意:如果auto_increment_offset起始偏移量的值大于auto_increment_increment 布长 的值,
则auto_increment_offset 布长的值会被忽略
起始偏移量一定要<=布长
set global auto_increment_offset=4;
mysql> set global auto_increment_increment=5;
Query OK, 0 rows affected (0.00 sec) mysql> set global auto_increment_offset=3;
Query OK, 0 rows affected (0.00 sec) mysql> exit
Bye
修改后要退出 重新登录mysql 再查看
mysql> show variables like "auto_inc%";
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 5 |
| auto_increment_offset | 3 |
+--------------------------+-------+
2 rows in set (0.00 sec)
再创建一张 t21表
mysql> create table t21(
-> id int primary key auto_increment,
-> name char(16)
-> );
Query OK, 0 rows affected (0.01 sec) mysql> desc t21;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(16) | YES | | NULL | |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
mysql> insert into t21(name) values('alex'),('mike'),('jack'),('peter');
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from t21;
+----+-------+
| id | name |
+----+-------+
| 3 | alex |
| 8 | mike |
| 13 | jack |
| 18 | peter |
+----+-------+
4 rows in set (0.00 sec)
mysql 约束条件 auto_increment 自动增长起始值 布长 起始偏移量的更多相关文章
- mysql 约束条件 auto_increment 自动增长 修改自增字段起始值
创建一张表 t20 mysql) ); Query OK, rows affected (0.01 sec) mysql> desc t20; +-------+----------+----- ...
- mysql 约束条件 auto_increment 自动增长目录
mysql 约束条件 auto_increment 自动增长 mysql 约束条件 auto_increment 自动增长起始值 布长 起始偏移量 mysql 约束条件 auto_increment ...
- mysql 约束条件 auto_increment 自动增长
约束字段为自动增长,被约束的字段必须同时被key约束 id自动增长,每插入一条记录,自动增长 创建一张表 t20 id 字段设置为 不为空 唯一 自动增长 mysql)); Query OK, row ...
- mysql 约束条件 auto_increment 自动增长 清空表 自动增长情况
清空表情况: mysql> delete from t20; Query OK, rows affected (0.00 sec) mysql> show create table t20 ...
- mysql 约束条件 auto_increment 自动增长 创建表时设置自增字段
auto_increment mysql) )auto_increment; Query OK, rows affected (0.01 sec) mysql> show create tabl ...
- mysql 更改自动增长字段值的重新设定
今天在服务器上MYSQL库里的一个表插入数据,主键id是auto_increment自动增长类型的.发现插入的值从2247734开始,而实际上id的最大值才22722,不明原因. 删除了新增的,opt ...
- PowerDesigner 15设置mysql主键自动增长及基数
PowerDesigner 15设置mysql主键自动增长及基数 1.双击标示图,打开table properties->columns, 如图点击图标Customize Columns an ...
- 140304笔记, mysql 更改自动增长字段值的重新设定
1. 存在同名的或不同的namespace交错情况. Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result m ...
- mysql 修改已存在的表增加ID属性为auto_increment自动增长
今天有需要将已经存在表设置自动增长属性 具体如下 alter table customers change id id int not null auto_increment primary key; ...
随机推荐
- iOS: UUID and SSKeyChain
需要加入SSKeyChain文件 传送门:SSKeyChain // // UniqueIDCreater.h // Housemart // // Created by Haozhen Li on ...
- 【算法】CRF
http://www.open-open.com/doc/view/7e983c0bf1594849bcd088dc212098c4 http://wenku.baidu.com/link?url=c ...
- Dll 使用 PChar 参数的小例子 - 回复 "linximf" 的问题
本例效果图: Dll 文件: library Lib; uses SysUtils, Classes; {$R *.res} procedure Test(p: PChar); const T ...
- Emulator Error: Could not load OpenGLES emulation library: Could not load DLL!
Copy the file below from SDK\tools\lib to SDK\tools. libEGL_translator.dlllibGLES_CM_translator.dlll ...
- laravel 查询构建器(连贯操作)
注:laravel 查询返回行的都是 php 的 stdClass 对象实例,不是数组!!!! 1)查询多行(get) DB::table('table_name')->get(); 带偏移和限 ...
- [转载]Linux I/O 调度方法
http://scoke.blog.51cto.com/769125/490546 IO调度器的总体目标是希望让磁头能够总是往一个方向移动,移动到底了再往反方向走,这恰恰就是现实生活中的电梯模型,所以 ...
- Linux curl 命令
curl is a tool to transfer data from or to a server, using one of the supported protocols ( http ,ht ...
- Python 数据类型:元组
一.元组介绍 1. 元组可以存储一系列的值,使用括号来定义,每个元素之间用逗号隔开,形如 ('a', 'b', 'c', 'd')2. 元组一旦定义,元组内的元素就不能再修改,除非重新定义一个新的元组 ...
- Effective C++ —— 设计与声明(四)
条款18 : 让接口容易被正确使用,不易被误用 欲开发一个“容易被正确使用,不容易被误用”的接口,首先必须考虑客户可能做出什么样的错误操作. 1. 明智而审慎地导入新类型对预防“接口被误用”有神奇疗 ...
- OpenGL ES2学习笔记(6)-- Line Strip和Line Loop
Line Strip 上一篇文章画了两条线段,但是用了4个点.如果几条线段首尾相接的话,可以让OpenGL把他们当成Line Strip来画,这样就可以用n+1个点来画n条线段. 代码 import ...