数据库

 首页 > 数据库 > MySql > mysql自增ID起始值修改方法

mysql自增ID起始值修改方法

分享到:
【字体:
导读:
         摘要:mysql自增ID起始值修改方法 ...

mysql自增ID起始值修改方法
在mysql中很多朋友都认为字段为AUTO_INCREMENT类型自增ID值是无法修改,其实这样理解是错误的,下面介绍mysql自增ID的起始值修改与设置方法。
通常的设置自增字段的方法:

创建表格时添加:

create table table1(id int auto_increment primary key,...)

创建表格后添加:

alter table table1 add id int auto_increment primary key 自增字段,一定要设置为primary key.

许多时候希望table中数据的id不要从1开始,像qq, id从10000开始
代码如下:

创建表格时添加:

CREATE TABLE `orders` (
  `order_num` int(11) NOT NULL auto_increment,
  `order_date` datetime NOT NULL,
  `cust_id` int(11) NOT NULL,
  PRIMARY KEY  (`order_num`),
  KEY `fk_orders_customers` (`cust_id`),
  CONSTRAINT `fk_orders_customers` FOREIGN KEY (`cust_id`) REFERENCES `customers` (`cust_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8;


创建表格后添加:

alter table users AUTO_INCREMENT=10000;

而且该语句也适用于修改现有表的id上, 比如大批量删除数据后,想id从654321退回123456开始

alter table users AUTO_INCREMENT=123456;


mysql自增ID起始值修改方法
分享到:
Oracle数据库连接检测(Shell)1 版本信...
Oracle数据库连接检测(Shell)1 版本信息 Oracle数据库版本:Oracle Release 10.2.0.1.0 系统版本:Red Hat EnterpriseLinux 5.4   2 检测步骤 2.1 编写Shell脚本 在有SQLPLUS执行权限的用户下,编辑check_oracle_connection.sh脚本。 vi check_oracle_connection.sh编辑内容如下:#!/bin/bash #functions: connect oracl...
ORA-38760: This database instance fail...
ORA-38760: This database instance failed to turn on flashback database 第三篇ORA-38760: This database instance failed to turn on flashback database  第三篇   第一篇 第二篇 问题现象:      在数据库alert告警日志中看见如下信息: Completed: ALTER DATABASE MOUNT Wed Nov 19 04:57:28 2014 alter dat...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……