SQLite User Forum

Add Columns
Login

Add Columns

(1) By anonymous on 2022-04-27 17:49:18 [link] [source]

Hello

I'm using '2.8.13' version

My query is :

ALTER TABLE customers ADD b_name text;

SQLITE return ' syntax error near ALTER '

how can I add a new columns ?

thanks

(2) By Stephan Beal (stephan) on 2022-04-27 17:53:18 in reply to 1 [link] [source]

I'm using '2.8.13' version ... how can I add a new columns ?

You need to upgrade to a version which was released more recently than 18 years ago.

(3) By anonymous on 2022-04-28 07:07:13 in reply to 2 [link] [source]

Yes I knom :-)
but anyway, can I add a column with this version ?

thanks

(4.1) By Warren Young (wyoung) on 2022-04-28 08:45:24 edited from 4.0 in reply to 3 [link] [source]

Follow the procedure here.

(5) By anonymous on 2022-04-30 11:20:18 in reply to 4.1 [source]

YES ! perfect !

begin transaction; CREATE TABLE temptable ..... INSERT INTO temptable SELECT *, '' FROM Customers; DROP TABLE Customers; ALTER TABLE temptable RENAME TO Customers; COMMIT;

thanks

(6) By Aask (AAsk1902) on 2022-04-30 20:54:25 in reply to 5 [link] [source]

perfect !

Really? Where were any new column(s) added?

(7) By Larry Brasfield (larrybr) on 2022-04-30 21:11:21 in reply to 6 [link] [source]

CREATE TABLE temptable ..... ... perfect !

Really? Where were any new column(s) added?

Perhaps the ellipsis stood in for that and other details of the CREATE statement.

(8.1) By Aask (AAsk1902) on 2022-04-30 22:33:57 edited from 8.0 in reply to 7 [link] [source]

Perhaps the ellipsis stood in for that and other details of the CREATE statement.

I don't think so. If that were the case consider the clause

INSERT INTO temptable SELECT *, '' FROM Customers;

There should have been an enumeration of the existing column names after INSERT INTO template

(9) By Aask (AAsk1902) on 2022-04-30 22:47:27 in reply to 7 [link] [source]

Perhaps the ellipsis stood in for that and other details of the CREATE statement.

Larry, you are right!

The clue is in:

SELECT *, '' FROM Customers;

It looks like ONE column was added at the end of the existing columns in the table and its value coerced to an empty string ... so the enumeration of the existing column names was not necessary.