SQL/Attributes/AUTO INCREMENT

Материал из Энциклопедия о программировании
Перейти к: навигация, поиск

AUTO_INCREMENT is a table global attribute can be used to automatic generate a unique identity for new rows of table.

Create table with field with AUTO_INCREMENT attribute and install counter of AUTO_INCREMENT to 1:

CREATE TABLE `tbl` (
	`id` INT(10) AUTO_INCREMENT,
	PRIMARY KEY (`id`),
)
COMMENT=''
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1;

Change current AUTO_INCREMENT counter in table:

ALTER TABLE `table` AUTO_INCREMENT=50;

Links