sql >> Database >  >> RDS >> Mysql

voeg autoincrement in tweede kolom in

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. JPA flush vs commit

  2. SUM() Functie in SQL Server

  3. Een door komma's gescheiden kolom optellen in MySQL 4 (niet 5)

  4. Converteer een complexe SQL-query naar SQLAlchemy