Adding or removing an auto-incrementing integer column to a table which does not have one via the table view generates code which cannot run without being edited.
DBeaver Version
24.2.0
Operating System
macOS
Database and driver
MariaDB 11
Steps to reproduce
Create a table with a varchar column
Edit the table via the GUI and add a new column like so:
Click OK. Notice the "Key" column for the new column is not populated
Click Save to get the following code:
ALTER TABLE mytable ADD id INT auto_increment NOT NULL;
ALTER TABLE mytable ADD CONSTRAINT `primary` PRIMARY KEY (id);
Clicking Execute will generate an error:
SQL Error [1075] [42000]: (conn=107406) Incorrect table definition; there can be only one auto column and it must be defined as a key
(conn=107406) Incorrect table definition; there can be only one auto column and it must be defined as a key
The correct sql to add such a column is:
ALTER TABLE mytable ADD id INT auto_increment NOT NULL PRIMARY KEY
Once the column is added to the table, delete it via the GUI
Answer "Yes" to both questions
Click Save to get the following code:
ALTER TABLE mytable DROP PRIMARY KEY;
ALTER TABLE mytable DROP COLUMN view_id;
Clicking Execute will generate an error:
SQL Error [1075] [42000]: (conn=107406) Incorrect table definition; there can be only one auto column and it must be defined as a key
(conn=107406) Incorrect table definition; there can be only one auto column and it must be defined as a key
The correct way to drop such a column is to drop the column first, then the primary key:
ALTER TABLE mytable DROP COLUMN view_id;
ALTER TABLE mytable DROP PRIMARY KEY;
Description
Adding or removing an auto-incrementing integer column to a table which does not have one via the table view generates code which cannot run without being edited.
DBeaver Version
24.2.0
Operating System
macOS
Database and driver
MariaDB 11
Steps to reproduce
The correct sql to add such a column is:
The correct way to drop such a column is to drop the column first, then the primary key:
Additional context
No response