On Wed, 5 Dec 2007 09:56:30 -0800 (PST), Joanne Pham
<[EMAIL PROTECTED]> wrote:
>Hi All,
>Is it possible to check if the certain column is existed in the table.
>For example : I had the table as define below:
> create table tablea (appid int, bytesIn int, bytesOut int)
You can get information about columns in a table with
PRAGMA table_info(tablea);
>and I want to add one more column with default
>value of 1 and I don't want to drop the table
>and recreate it again because I want to keep
>the data in the table.
-- rename the original table
ALTER TABLE tablea RENAME TO tablea_old;
-- create the new table
CREATE TABLE tablea (
appid int,
bytesIn int,
bytesOut int,
newcol int DEFAULT 1
);
-- Load data into the new table
INSERT INTO tablea (appid, bytesIn, bytesOut)
SELECT appid, bytesIn, bytesOut
FROM tablea_old;
-- Drop the original table
DROP TABLE tablea_old;
-- optimize the database
VACUUM;
ANALYZE;
>Thanks,
>jp
HTH
--
( Kees Nuyt
)
c[_]
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------