← Back to team overview

maria-developers team mailing list archive

WL#252 New (by DonQuichote): IF (NOT) EXIST clauses for ALTER TABLE

 

-----------------------------------------------------------------------
                              WORKLOG TASK
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TASK...........: IF (NOT) EXIST clauses for ALTER TABLE
CREATION DATE..: Fri, 01 Jun 2012, 09:35
SUPERVISOR.....: 
IMPLEMENTOR....: 
COPIES TO......: 
CATEGORY.......: Server-RawIdeaBin
TASK ID........: 252 (https://askmonty.org/worklog/?tid=252)
VERSION........: WorkLog-4.0
STATUS.........: Un-Assigned
PRIORITY.......: 60
WORKED HOURS...: 0
ESTIMATE.......: 0 (hours remain)
ORIG. ESTIMATE.: 0

PROGRESS NOTES:



DESCRIPTION:

MySQL / MariaDB SQL is great as a functional language: you tell what you want
and not how to do it. This includes suppressing of errors when the situation you
want already exists. So there is a CREATE TABLE IF NOT EXISTS statement, for
example (you say that you want the table to exist, not that it has to be built
right now). It would be nice if altering a table could be done the same way:

ALTER TABLE SomeTable ADD COLUMN IF NOT EXISTS SomeColumn ...

ALTER TABLE SomeTable DROP COLUMN IF EXISTS SomeColumn ...

ALTER TABLE SomeTable DROP FOREIGN KEY IF EXISTS SomeConstraint ...

This would make definition scripts more legible and more friendly to existing
databases. It would facilitate what I call "repeatable scripts", that can both
create a new database and update an existing one to the latest structure.

Mind you, this is already possible using temporary stored procedures (as shown
in http://www.howtoforge.com/node/4833), but it would make definition scripts
more maintainable and the SQL language more consistent.


ESTIMATED WORK TIME

ESTIMATED COMPLETION DATE
-----------------------------------------------------------------------
WorkLog (v4.0.0)