Page 1 of 1

Alter Table syntax - SQLite

Posted: Sat Aug 01, 2015 3:09 am
by quailcreek
Hi,
I have 2 question regarding ALTER TABLE.

1) How do I define the column type. Defined like this when a TABLE is created, RowStyle TEXT
2) Does SQLite have the IF DOES NOT EXIST syntax? If so how would I incorporate it into this code. If not, how can it be done?

Code: Select all

 put "RowStyle" into pRowStyle
   put "ALTER TABLE MyItems ADD COLUMN '"&pRowStyle&"'" into tAddColumn
   revExecuteSQL  the uDatabaseID of this stack ,tAddColumn
Thanks for any help.

Re: Alter Table syntax - SQLite

Posted: Sat Aug 01, 2015 7:56 pm
by phaworth
SQLite does have IF NOT EXISTS on the CREATE xxx commands but not on the ALTER Table command. If you need to check for the existence of a column before executing the ALETR TABLE command, try using the revDatabaseColumnNames command and checking the output. Or you can revDataFromQuery with a PRAGMA table_info(tablename). Or you could just execute the ALETR TABLE and check for an error.

To define the column type, it's the same syntax as with CREATE TABLE, so:

Code: Select all

put "ALTER TABLE 'MyItems' ADD COLUMN '" & prowstyle & "'" && "TEXT" into tAddColumn
Pete

Re: Alter Table syntax - SQLite

Posted: Sat Aug 08, 2015 4:43 am
by quailcreek
Great, thanks a lot Pete.