mysql序列是一组整数:1,2,3....,由于一张数据表只能有一个字段自增主键,如果你想实现其他字段自动增加,就可以使用mysql序列来实现。

使用auto_increment来定义列

drop table if EXISTS test_autoincrement ;
create table `test_autoincrement`(
`id` int UNSIGNED not null auto_increment,
PRIMARY KEY (id),
`name` varchar(20) not null,
`date` date not null,
`origin` varchar(30)
);
insert into test_autoincrement (name,date,origin) values
('housefly','2001-09-10','kitchen');
-- 使用last_insert_id() 可以查看当前操作的次数
select LAST_INSERT_ID();
select * from test_autoincrement;
insert into test_autoincrement values
(null,"millipede",'2001-09-10','driverway'),
(null,"grasshopper",'2001-09-10','front yard');
-- 即便插入多行,也只显示插入第一行时产生的值
select LAST_INSERT_ID();
select * from test_autoincrement;

重置序列

先删除列,再添加列

drop table if EXISTS test_autoincrement ;
create table `test_autoincrement`(
`id` int UNSIGNED not null auto_increment,
PRIMARY KEY (id),
`name` varchar(20) not null,
`date` date not null,
`origin` varchar(30)
);
insert into test_autoincrement (name,date,origin) values
('housefly','2001-09-10','kitchen'),
("millipede",'2001-09-10','driverway'),
("grasshopper",'2001-09-10','front yard');
alter table test_autoincrement drop id;
select * from test_autoincrement;
alter table test_autoincrement add id int(3) UNSIGNED not null auto_increment FIRST,
add primary key (id);
select * from test_autoincrement;

设置序列的开始值

建表时设置序列值

create table `test_autoincrement`
(`id` int(3) UNSIGNED not null auto_increment,
primary key (id),
`name` varchar(20) not null )
engine=innodb auto_increment=100 charset=utf8;
insert into test_autoincrement values
(null,"tom"),
(null,"jerry");
select * from test_autoincrement;

mysql-12序列使用的更多相关文章

  1. Mysql的序列

    Mysql的序列 Mysql自带的序列:字段设置为int,属性里面选上“自动增长”即可: 在插入数据的时候可以不插入该字段的值,mysql会自动处理:

  2. 11、可扩展MySQL+12、高可用

    11.1.扩展MySQL 静态分片:根据key取hash,然后取模: 动态分片:用一个表来维护key与分片id的关系: 11.2.负载均衡 12. 12.2导致宕机得原因: 35%环境+35%性能+2 ...

  3. Oracle 学习笔记 12 -- 序列、索引、同义词

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/Topyuluo/article/details/24232449 数据库的对象包含:表.视图.序列. ...

  4. Oracle与Mysql操作表序列

    一.Oracle添加表序列 CREATE SEQUENCE name -- 序列名 INCREMENT BY -- 每次加几个 START WITH -- 从几开始计数 MINVALUE --- 最小 ...

  5. MySQL --12 备份的分类

    目录 物理备份(Xtrabackup) 1.全量备份 2.增量备份及恢复 3.差异备份及恢复 4.实战:企业级增量恢复实战 物理备份(Xtrabackup) Xtrabackup安装 #下载epel源 ...

  6. mysql#自定义序列

    原文 mysql主键不用自增数字的时候,可以参考如下方式,我抄来的. -- 创建公共的序列表 DROP TABLE IF EXISTS t_common_sequence; CREATE TABLE ...

  7. mysql> 12 simple but staple commands

    Edit at:  2019-12-28 16:52:42 1.mysql -u+username -p+password  --> connect mysql 2.use databasena ...

  8. 【网站建设】Linux上安装MySQL - 12条命令搞定MySql

    从零开始安装mysql数据库 : 按照该顺序执行 :  a. 查看是否安装有mysql:yum list installed mysql*, 如果有先卸载掉, 然后在进行安装; b. 安装mysql客 ...

  9. oracle mysql的序列的新增、删除、修改及使用

    序列的使用  参考文献: https://blog.csdn.net/meijory/article/details/51891529 1.序列介绍 序列: 是 oracle 提供的用于产生一系列唯一 ...

  10. mysql 12小时和24小时转换

    1.12小时显示 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String ...

随机推荐

  1. TCGA系列--TCGA可视化数据库GEPIA

    中国大牛力作  张泽民: http://gepia.cancer-pku.cn/index.html http://cancer-pku.cn/

  2. django urlencode

    from django.utils.http import urlquote a = urlquote('分享') print(a)

  3. python 去除字符串两端的引号

    a='"srting"' print(a) b=eval(a) print(b) 输出 "srting" srting

  4. Qt5发布错误01

    1.Qt5+VS2013兼容XP方法 (http://www.qtcn.org/bbs/apps.php?q=diary&a=detail&did=2047&uid=15538 ...

  5. TensorFlow实现FM

    看了网上的一些用tf实现的FM,很多都没有考虑FM实际使用中数据样本稀疏的问题. 我在实现的时候使用 embedding_lookup_sparse来解决这个问题. 对于二阶部分,由于embeddin ...

  6. kue

    尝试着看英文的文档,你发现他其实并不难. https://www.npmjs.com/package/kue

  7. ListBox的虚拟可视化技术

    在ListBox中承载大量的数据项时,可采用虚拟可视化技术来提高控件显示数据的性能.如下代码: <ListBox.ItemsPanel>                    <It ...

  8. poj2411 轮廓线dp裸题

    题意:用12的骨牌覆盖nm的矩阵的方案数 题解:dp[i][j]表示枚举到了第i行,j状态的方案数,三种转移,向上的,要求不是第一行而且上面的没有覆盖过,向下的,要求不是第一列而且左边没有覆盖过,不放 ...

  9. access_token和微信服务地址的获取

    access_token的获取: //获取微信服务器地址:

  10. hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1

    Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...