sql >> Databasteknik >  >> RDS >> Mysql

infoga autoincrement i den andra kolumnen

mysql> describe concattest;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| val   | text             | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> INSERT INTO concattest (val) VALUES (concat('val', LAST_INSERT_ID()));
Query OK, 1 row affected (0.06 sec)

mysql> select * from concattest;
+----+------+
| id | val  |
+----+------+
|  1 | val0 |
+----+------+
1 row in set (0.00 sec)

mysql> INSERT INTO concattest (val) VALUES (concat('val', LAST_INSERT_ID()));
Query OK, 1 row affected (0.00 sec)

mysql> select * from concattest;
+----+------+
| id | val  |
+----+------+
|  1 | val0 |
|  2 | val1 |
+----+------+
2 rows in set (0.00 sec)

mysql> INSERT INTO concattest (val) VALUES (concat('val', LAST_INSERT_ID()));
Query OK, 1 row affected (0.00 sec)

mysql> select * from concattest;
+----+------+
| id | val  |
+----+------+
|  1 | val0 |
|  2 | val1 |
|  3 | val2 |
+----+------+
3 rows in set (0.00 sec)



  1. Ta bort de två sista tecknen i en kolumn i MySQL

  2. Assembly 'Microsoft.SqlServer.Types' version 10 eller högre kunde inte hittas

  3. Ruby, Rails:mysql2 pärla, använder någon denna pärla? Är det stabilt?

  4. Hur man läser MySQL binära loggfiler (BinLog) med mysqlbinlog