Oracle 5.0 Reference Manual page 241

Table of Contents

Advertisement

CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM;
INSERT INTO animals (name) VALUES
('dog'),('cat'),('penguin'),
('lax'),('whale'),('ostrich');
SELECT * FROM animals;
Which returns:
+----+---------+
| id | name
|
+----+---------+
|
1 | dog
|
|
2 | cat
|
|
3 | penguin |
|
4 | lax
|
|
5 | whale
|
|
6 | ostrich |
+----+---------+
No value was specified for the
automatically. You can also explicitly assign
You can retrieve the most recent
function or the
mysql_insert_id()
return values are not affected by another connection which is also performing inserts.
Use a large enough integer data type for the
sequence value you will need. When the column reaches the upper limit of the data type, the next
attempt to generate a sequence number fails. For example, if you use TINYINT, the maximum
permissible sequence number is 127. For
Note
For a multiple-row insert,
mysql_insert_id()
first of the inserted rows. This enables multiple-row inserts to be reproduced
correctly on other servers in a replication setup.
For
and
tables you can specify
MyISAM
BDB
column index. In this case, the generated value for the
MAX(auto_increment_column) + 1 WHERE prefix=given-prefix
when you want to put data into ordered groups.
CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
) ENGINE=MyISAM;
INSERT INTO animals (grp,name) VALUES
('mammal','dog'),('mammal','cat'),
('bird','penguin'),('fish','lax'),('mammal','whale'),
('bird','ostrich');
SELECT * FROM animals ORDER BY grp,id;
Which returns:
+--------+----+---------+
| grp
| id | name
Using
AUTO_INCREMENT
AUTO_INCREMENT
NULL
AUTO_INCREMENT
C API function. These functions are connection-specific, so their
AUTO_INCREMENT
TINYINT
LAST_INSERT_ID()
actually return the
AUTO_INCREMENT
|
221
column, so MySQL assigned sequence numbers
or 0 to the column to generate sequence numbers.
value with the
LAST_INSERT_ID()
column to hold the maximum
UNSIGNED, the maximum is 255.
[961]
and
AUTO_INCREMENT
on a secondary column in a multiple-
AUTO_INCREMENT
[961]
SQL
key from the
column is calculated as
[971]. This is useful

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents