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.
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;
I did today ALTER TABLE table_name DROP IF EXISTS column_name; and it works :P
MariaDB 10.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With