AUTO_INCREMENT

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Spiegazione

L'attributo AUTO_INCREMENT è utile per generare un'identità univoca per le righe.

Esempi

CREATE TABLE animali (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     nome CHAR(30) NOT NULL,
     PRIMARY KEY (id)
 );

INSERT INTO animals (nome) VALUES
    ('cane'),('gatto'),('pinguino'),
    ('volpe'),('balena'),('ostrica');
MariaDB [test]> SELECT * FROM animals;
+----+----------+
| id | nome     |
+----+----------+
|  1 | cane     |
|  2 | gatto    |
|  3 | pinguino |
|  4 | volpe    |
|  5 | balena   |
|  6 | ostrica  |
+----+----------+
6 rows in set (0.01 sec)

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.