We have quite a few databases, and we're trying to run upgrade scripts on all of them to bring them up to date - as such, they all have different columns and tables.
We want to add new tables and columns if they arent already present, so for instance
CREATE TABLE IF NOT EXISTS `orders` ( `id` INT (11) NOT NULL ,
`value` VARCHAR (50) , `designId` INT (11) , PRIMARY KEY ( `id`));
That works, but we're looking for the same kind of solution for columns. Our current solution throws Error Code: 1060 - Duplicate column name.
ALTER TABLE `orders` ADD COLUMN `customer` INT (1) NULL;
I've tried the following from garry passarella, but i get an error claiming incorrect sql syntax:
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'orders' AND COLUMN_NAME = 'customer')
BEGIN ALTER TABLE orders
ADD customer BIT DEFAULT NULL
END
If there is something we can use to get each line to ignore duplicates, or get the entire script to ignore error code 1060, it would be much appreciated.