I need to run this MySql code on some databases and I suspect that some of them to have already this column. Is there anything similar to if not exists for the below code?
ALTER TABLE
`comments`
ADD COLUMN
`active` int(1) NOT NULL DEFAULT '0' AFTER `sid`
I’m considering this to prevent getting the duplicated column error.
It’s not built-in, but it can be accomplished using the information_schema database:
http://www.cryer.co.uk/brian/mysql/howto_add_column_unless_exists.htm