- Notifications
You must be signed in to change notification settings - Fork689
INSERT
Mathias Wulff edited this pageDec 15, 2025 ·2 revisions
Syntax:
INSERT INTO table [(column1, column2...)] [VALUE[S]] valuePair1, valuePair2, ...;INSERT INTO table DEFAULTVALUES;INSERT INTO tableSELECT ...; INSERT [IGNORE] INTO table ...;INSERT INTO tableSET column1= value1, column2= value2, ...;
[INSERT [VALUES]](Insert Values)
alasql('INSERT INTO city (name, population) VALUES ("Moscow",11500000), ("Kyiv",5000000)');alasql('INSERT INTO city VALUES {population:4000000, name:"Berlin"}');alasql('INSERT INTO city VALUES ?',[data]);alasql('INSERT INTO city VALUES ("Copenhagen",1000000)');alasql('INSERT INTO city VALUE ("Barcelona",1600000)');alasql('INSERT INTO city ("Paris",3500000)');
[INSERT DEFAULT VALUES](Insert Default Values)
alasql('INSERT INTO city DEFAULT VALUES');
[INSERT SELECT](Insert Select) (equivalent of SELECT INTO)
alasql('INSERT INTO city SELECT capital AS name FROM country GROUP BY capital;');
You can useINSERT IGNORE to skip rows that would cause a constraint violation (like duplicate primary keys).
alasql('INSERT IGNORE INTO city VALUES ("Paris", 3500000)');
You can useSET syntax to specify column values, similar to UPDATE syntax.
alasql('INSERT INTO city SET name = "Madrid", population = 3000000');
You can use theOUTPUT clause to return the inserted data. This is useful when you want to get the generated IDs or default values.
// Return all inserted columnsalasql('INSERT INTO city VALUES ("Rome", 2800000) OUTPUT INSERTED.*');// Return specific columnsalasql('INSERT INTO city VALUES ("Rome", 2800000) OUTPUT INSERTED.name, INSERTED.population');
AnINSERT statement will return the amount of rows inserted by the statment.
See also:INTO, [SELECT INTO](Select Into)
© 2014-2026,Andrey Gershun &Mathias Rangel Wulff
Please help improve the documentation by opening a PR on thewiki repo