On 16 Dec 2014, at 10:40pm, Nico Williams <n...@cryptonector.com> wrote:

> I have a habit of putting schema definitions in a file that's always
> safe to read and execute against a DB connection.  This means that I
> DROP some things IF EXISTS and CREATE all things IF NOT EXISTS.
> 
> But if I have to ALTER TABLE... there's no IF NOT EXISTS .. equivalent
> for ALTER TABLE.
> 
> Funny that, or that I only just noticed this absence.
> 
> Looking at other SQL databases I see that this is actually a common
> question/request, and it seems that where this is implemented it looks
> like this:
> 
>  ALTER TABLE [IF EXISTS] <tbl> ADD COLUMN <col> [IF NOT EXISTS] ..;

If 'ALTER TABLE ... ADD COLUMN ...' fails it fails harmlessly, with its work 
already having been done.  The ALTER command came along a long time after 
original SQL.  By that time software could handle cases where a single SQL 
command failed without the software having to crash at that point.

In other words a programmer could execute the ALTER command, and if if failed 
carry on regardless, or use that failure to skip over more code which set up 
initial values in the new column.

I would value far more the ability to do

ALTER TABLE ... DROP COLUMN ...

in SQLite, difficult though it would be to implement in SQLite3.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to