Skip to content

Instantly share code, notes, and snippets.

@jdmullin
Created July 15, 2013 17:11
Show Gist options
  • Save jdmullin/6001655 to your computer and use it in GitHub Desktop.
Save jdmullin/6001655 to your computer and use it in GitHub Desktop.
Older pattern for idempotent alter scripts
SELECT count(*)
INTO @exist
FROM information_schema.columns
WHERE table_schema = 'databaseName'
and COLUMN_NAME = 'columnName'
AND table_name = 'tableName';
set @query = IF(@exist <= 0,
'alter table whatever',
'select \'Column already exists\' status');
prepare stmt from @query;
EXECUTE stmt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment