Reputation: 1343
Can someone explain me, what's wrong with my SQL query?
ALTER TABLE tableName DROP COLUMN IF EXISTS columnName;
MariaDB gives me this error:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax
to use near 'IF EXISTS columnName' at line 1
A tried a lot of syntax modification, but without positive result.
Upvotes: 4
Views: 9269
Reputation: 132
For newer versions:
ALTER TABLE table_name DROP COLUMN column_name;
Upvotes: -2
Reputation: 31
I did today ALTER TABLE table_name DROP IF EXISTS column_name;
and it works :P
MariaDB 10.0
Upvotes: 0
Reputation: 5060
I tested it on dbfiddle.uk (MariaDB 10.2 RC) and it works. Are you sure about your MariaDB version (SELECT VERSION();
) and the presence of the command in that version? (I suppose it doesn't support until MARIADB 10)
CREATE TABLE T1 (ID INT, DESCR VARCHAR(20));
INSERT INTO T1 VALUES (1, 'Test');
SELECT * FROM T1;
ALTER TABLE T1 DROP COLUMN IF EXISTS XXX; /* no error */
SELECT * FROM T1;
ALTER TABLE T1 DROP COLUMN IF EXISTS DESCR; /* column dropped*/
SELECT * FROM T1;
Upvotes: 3