mysql-12序列使用
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序列使用的更多相关文章
- Mysql的序列
Mysql的序列 Mysql自带的序列:字段设置为int,属性里面选上“自动增长”即可: 在插入数据的时候可以不插入该字段的值,mysql会自动处理:
- 11、可扩展MySQL+12、高可用
11.1.扩展MySQL 静态分片:根据key取hash,然后取模: 动态分片:用一个表来维护key与分片id的关系: 11.2.负载均衡 12. 12.2导致宕机得原因: 35%环境+35%性能+2 ...
- Oracle 学习笔记 12 -- 序列、索引、同义词
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/Topyuluo/article/details/24232449 数据库的对象包含:表.视图.序列. ...
- Oracle与Mysql操作表序列
一.Oracle添加表序列 CREATE SEQUENCE name -- 序列名 INCREMENT BY -- 每次加几个 START WITH -- 从几开始计数 MINVALUE --- 最小 ...
- MySQL --12 备份的分类
目录 物理备份(Xtrabackup) 1.全量备份 2.增量备份及恢复 3.差异备份及恢复 4.实战:企业级增量恢复实战 物理备份(Xtrabackup) Xtrabackup安装 #下载epel源 ...
- mysql#自定义序列
原文 mysql主键不用自增数字的时候,可以参考如下方式,我抄来的. -- 创建公共的序列表 DROP TABLE IF EXISTS t_common_sequence; CREATE TABLE ...
- 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 ...
- 【网站建设】Linux上安装MySQL - 12条命令搞定MySql
从零开始安装mysql数据库 : 按照该顺序执行 : a. 查看是否安装有mysql:yum list installed mysql*, 如果有先卸载掉, 然后在进行安装; b. 安装mysql客 ...
- oracle mysql的序列的新增、删除、修改及使用
序列的使用 参考文献: https://blog.csdn.net/meijory/article/details/51891529 1.序列介绍 序列: 是 oracle 提供的用于产生一系列唯一 ...
- mysql 12小时和24小时转换
1.12小时显示 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String ...
随机推荐
- BZOJ 3876 【AHOI2014】 支线剧情
题目链接:支线剧情 这道题就是一道裸裸的上下界网络流……只不过这道题边带了权,那么建出图之后跑费用流即可. 首先需要新建超级源\(S\)和超级汇\(T\).对于这道题,对于一条边\((u,v,z)\) ...
- BZOJ 3238 【AHOI2013】 差异
题目链接:差异 写题时发现这道题当初已经用后缀数组写过了……但是既然学了后缀自动机那就再写一遍吧…… 观察一下题目所给的式子:\[\sum_{1\leqslant i < j \leqslant ...
- Rails 5 Test Prescriptions 第10章 Unit_Testing JavaScript(新工具,learn曲线太陡峭,pass)
对Js的单元测试是一个大的题目.作者认为Ruby的相关测试工具比Js的测试工具更灵活 大多数Js代码最终是关于响应用户的行为和改变DOM中的元素 没有什么javascript的知识点.前两节用了几个新 ...
- Confluence 6 创建一个用户宏
如果你想创建自定义的宏的话,用户宏能够帮你完成这个任务.这个可以在你系统中应用特定的操作,比如说应用自定义格式等. 用户用是在 Confluence 创建和和管理的,你需要有一定的编码基础才可以. 你 ...
- bzoj-3195-状压dp
3195: [Jxoi2012]奇怪的道路 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 600 Solved: 395[Submit][Statu ...
- C#删除图片问题
public Image GetImage(string path) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess. ...
- [Python开发工具] Pycharm之快捷键
[Python开发工具] Pycharm之快捷键 1 全局搜索: Ctrl+Shift+F,不过PyCharm的更强大, 你可以点选左侧某个目录后再按Ctrl+Shift+F, 这样默认会搜索改目录; ...
- Fly Vim, First-Class
http://corner.squareup.com/2013/08/fly-vim-first-class.html Engineers at Square use a wide variety o ...
- POJ 1797 kruskal 算法
题目链接:http://poj.org/problem?id=1797 开始题意理解错.不说题意了. 并不想做这个题,主要是想测试kruskal 模板和花式并查集的正确性. 已AC: /* 最小生成树 ...
- SSH使用主机名访问
比如说A电脑已经和B电脑实现了ssh免密码登陆!但是A电脑通过 ssh B电脑的主机名称 不行! 解决办法: 01.修改A电脑中的hosts文件 vim /etc/hosts 02.进入编辑界面 ...