约束字段为自动增长,被约束的字段必须同时被key约束

id自动增长,每插入一条记录,自动增长

创建一张表 t20 id 字段设置为 不为空 唯一 自动增长

mysql> create table t20(id int not null unique auto_increment,name varchar(16));
Query OK, 0 rows affected (0.01 sec) mysql> desc t20;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

只对name字段插入记录,我们看到id自动递增

mysql> insert into t20(name) values('mike'),('alex'),('ben');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from t20;
+----+------+
| id | name |
+----+------+
| 1 | mike |
| 2 | alex |
| 3 | ben |
+----+------+
3 rows in set (0.00 sec)

针对id,name 插入也可以的

#也可以指定id 从7开始
mysql> insert into t20(id,name) values(7,'apple');
Query OK, 1 row affected (0.00 sec) mysql> select * from t20;
+----+-------+
| id | name |
+----+-------+
| 1 | mike |
| 2 | alex |
| 3 | ben |
| 7 | apple |
+----+-------+

再针对name插入记录 id是从上次插入的记录开始计算

mysql> insert into t20(name) values('mike1'),('alex2'),('jack1');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from t20;
+----+-------+
| id | name |
+----+-------+
| 1 | mike |
| 2 | alex |
| 3 | ben |
| 7 | apple |
| 8 | mike1 |
| 9 | alex2 |
| 10 | jack1 |
+----+-------+
7 rows in set (0.00 sec)

mysql 约束条件 auto_increment 自动增长的更多相关文章

  1. mysql 约束条件 auto_increment 自动增长目录

    mysql 约束条件 auto_increment 自动增长 mysql 约束条件 auto_increment 自动增长起始值 布长 起始偏移量 mysql 约束条件 auto_increment ...

  2. mysql 约束条件 auto_increment 自动增长起始值 布长 起始偏移量

    我们指定一个字段为自动增长,他默认从1开始自动增长,默认值为1,每次增长为1,步长为1 模糊查询 like % 代表任意个数字符 任意字符长度 查看mysql正在使用变量 show variables ...

  3. mysql 约束条件 auto_increment 自动增长 清空表 自动增长情况

    清空表情况: mysql> delete from t20; Query OK, rows affected (0.00 sec) mysql> show create table t20 ...

  4. mysql 约束条件 auto_increment 自动增长 创建表时设置自增字段

    auto_increment mysql) )auto_increment; Query OK, rows affected (0.01 sec) mysql> show create tabl ...

  5. mysql 约束条件 auto_increment 自动增长 修改自增字段起始值

    创建一张表 t20 mysql) ); Query OK, rows affected (0.01 sec) mysql> desc t20; +-------+----------+----- ...

  6. PowerDesigner 15设置mysql主键自动增长及基数

    PowerDesigner 15设置mysql主键自动增长及基数 1.双击标示图,打开table properties->columns,  如图点击图标Customize Columns an ...

  7. mysql 修改已存在的表增加ID属性为auto_increment自动增长

    今天有需要将已经存在表设置自动增长属性 具体如下 alter table customers change id id int not null auto_increment primary key; ...

  8. mysql——主键自动增长&唯一索引

    首先说一下主键和唯一索引的区别 主键:一个数据库的一张表有且仅有一个主键,而且主键不能重复 唯一索引:一个数据库的一张表上唯一索引可以有多个,只是所在唯一索引上的值不能重复,这一点和主键一样 下面我们 ...

  9. mysql 如何设置自动增长序列 sequence(一)

    背景:由于项目需要,必须用mysql设置主键自增长,而且想用字符串的.经过上网查找并且实验,终于做出了一套方案.现在就共享给大家! 解决思路:由于mysql不带sequence,所以要手写的,创建一张 ...

随机推荐

  1. MDI多文档窗体续

    private void 加载窗体_Click(object sender, EventArgs e) { Form2 frm = new Form2();//实例化 Form2 frm.MdiPar ...

  2. oozie常见错误问题

    1.  Error: HTTP error code: 404 : Not Found 原因: 在环境变量中配置的OOZIE_URL有问题配置成了 export OOZIE_URL=http://dw ...

  3. hdu6134 Battlestation Operational 莫比乌斯第一种形式

    /** 题目:hdu6134 Battlestation Operational 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134 题意:f(n) = ...

  4. hdu4746 Mophues 莫比乌斯

    /** 题目:hdu4746 Mophues 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4746 题意:求x,y在给定范围内gcd(x,y)分解素因子的 ...

  5. 微信小程序 - 开发工具之编译模式

    在开发中,遇到一个层级较深的页面,每次都要点击好多步才能调试,也比较闹心,有了自定义编译模式,就方便很多了 点击红圈处, 选择 "+添加编译模式" , 默认的, 启动页面会填入当前 ...

  6. Differential Geometry之第六章平面曲线的整体性质

    第六章.平面曲线的整体性质 1.平面的闭曲线 1.1.切线的旋转指数定理 1.2.等周不等式与圆的几何特性 ,其中 2.平面的凸曲线 支撑函数: 2.1.Minkowski问题 2.2.四顶点定理

  7. 下面哪些属于JSTL中的表达式操作标签。(选择1项)

    A.<c:out> B.<c:if> C.<c:url> D.<c:catch> 解答:A

  8. openstacksdk resource2 打印__dict__

    在一个继承resource2的实体里,打印self.__dict__结果是: {'_body': <openstack.resource2._ComponentManager object at ...

  9. 第十五篇:使用 FP-growth 算法高效挖掘海量数据中的频繁项集

    前言 对于如何发现一个数据集中的频繁项集,前文讲解的经典 Apriori 算法能够做到. 然而,对于每个潜在的频繁项,它都要检索一遍数据集,这是比较低效的.在实际的大数据应用中,这么做就更不好了. 本 ...

  10. 数据库为什么要用B+树结构--MySQL索引结构的实现(转)

    B+树在数据库中的应用 { 为什么使用B+树?言简意赅,就是因为: 1.文件很大,不可能全部存储在内存中,故要存储到磁盘上 2.索引的结构组织要尽量减少查找过程中磁盘I/O的存取次数(为什么使用B-/ ...