Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite alter table add MULTIPLE columns in a single statement

Is it possible to alter table add MULTIPLE columns in a single statement in sqlite? The following would not work.

alter table test add column mycolumn1 text, add column mycolumn2 text;
like image 354
user775187 Avatar asked Oct 04 '22 20:10

user775187


Video Answer


2 Answers

No, you have to add them one at a time. See the syntax diagram at the top of SQLite's ALTER TABLE documentation:

ALTER TABLE syntax

There's no loop in the ADD branch so no repetition is allowed.

like image 352
mu is too short Avatar answered Oct 07 '22 06:10

mu is too short


The only thing so far possible that I use is

BEGIN TRANSACTION;
ALTER TABLE tblName ADD ColumnNameA TEXT DEFAULT '';
ALTER TABLE tblName ADD ColumnNameB TEXT DEFAULT '';
ALTER TABLE tblName ADD ColumnNameC TEXT DEFAULT '';
COMMIT

Note that there are ; on purpose to make the query be read as multiple lines.

Then I run this query and get multiple columns added in on run... So no not in one line, but yes in one query its possible.

like image 8
Michiel Krol Avatar answered Oct 07 '22 04:10

Michiel Krol