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; ...
随机推荐
- SharePoint 2010 自定义页面出现“项目可能已被其他用户删除或重命名”问题跟踪
异常详细信息: Microsoft.SharePoint.SPException: 位置 http://portal/Pages/ShowArticle.aspx?id=19&mylist=8 ...
- sip 认证分析
转自:http://blog.csdn.net/wangqi0079/article/details/11569489 SIP类似Http协议.其认证模式也一样.Http协议(RFC 2616 )规定 ...
- python--数据类型--1
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 视频教程::http://www.imooc.com/learn/177 http://www. ...
- Spring------SpringBoot参考书籍
转载: http://download.csdn.net/download/plus_dy/8972653
- ios学习--TableView详细解释
-.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; [DataTa ...
- CSS3 属性组参考资料
CSS 属性组: 动画 背景 边框和轮廓 盒(框) 颜色 内容分页媒体 定位 可伸缩框 字体 生成内容 网格 超链接 行框 列表 外边距 Marquee 多列 内边距 分页媒体 定位 打印 Ruby ...
- [置顶] 数据库优化实践【MS SQL优化开篇】
数据库定义: 数据库是依照某种数据模型组织起来并存在二级存储器中的数据集合,此集合具有尽可能不重复,以最优方式为特定组织提供多种应用服务,其数据结构独立于应用程序,对数据的CRUD操作进行统一管理和控 ...
- java基础---->Java中图片的缩放
缩略图代表网页上或计算机中图片经压缩方式处理后的小图 ,其中通常会包含指向完整大小的图片的超链接.缩略图用于在 Web 浏览器中更加迅速地装入图形或图片较多的网页.今天,我们就开始java中图像的缩略 ...
- vux 头像上传
参考: http://blog.csdn.net/generon/article/details/72478269
- 《FPGA那些事儿》原创教程总结
经过我们黑金工程师多年的不断努力,黑金原创教程已经达到了14部,包括: 第一部:[黑金原创教程]NIOSII那些事儿 http://www.heijin.org/forum.php?mod=viewt ...