S
S
Sergey Korenevsky2021-09-28 16:40:05
MySQL
Sergey Korenevsky, 2021-09-28 16:40:05

How to add a column to a table in a MySQL query with a check for the presence of this column?

Dear Gurus and experts please give advice.
There is a narrow framework for creating a package.
-All queries must be packed into files with the SQL extension -Many queries are
stored in the SQL file
-In one of the queries, you need to add a column to the table, but you need to check for the absence of this column.

ALTER TABLE jshopping_orders ADD bonus varchar(24) NOT NULL DEFAULT '';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-09-28
@Dier_Sergio_Great

MariaDB allows the syntax:

ALTER TABLE jshopping_orders ADD COLUMN IF NOT EXISTS bonus varchar(24) NOT NULL DEFAULT '';

View MariaDB fiddle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question