Alter Table syntax - SQLite

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Alter Table syntax - SQLite

Post by quailcreek » Sat Aug 01, 2015 3:09 am

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.
Last edited by quailcreek on Sat Aug 08, 2015 4:46 am, edited 1 time in total.
Tom
MacBook Pro OS Mojave 10.14

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Alter Table syntax - SQLite

Post by phaworth » Sat Aug 01, 2015 7:56 pm

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

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Alter Table syntax - SQLite

Post by quailcreek » Sat Aug 08, 2015 4:43 am

Great, thanks a lot Pete.
Tom
MacBook Pro OS Mojave 10.14

Post Reply

Return to “Databases”