Hi Kees,
Is there anyway that we can find out how many columns are defined in the table?
Thanks for the info.
JP


----- Original Message ----
From: Kees Nuyt <[EMAIL PROTECTED]>
To: sqlite-users@sqlite.org
Sent: Wednesday, December 5, 2007 10:18:48 AM
Subject: Re: [sqlite] How to check if the column is existed in the table

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]
-----------------------------------------------------------------------------


      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Reply via email to