Search notes:

SQL: INSERT statement

The purpose of the insert statement is to add data (that is: create new records) to a table.

Insert a single record into a table

INSERT INTO target_table                VALUES (1, 'one');
INSERT INTO target_table (col_1, col_2) VALUES (2, 'two');

Insert multiple records in one go

The individual records to be inserted can be separated with commas:
INSERT INTO target_table VALUES
('record'    , 'one'   ),
('another'   , 'record'),
 …;
Note, that this variant does not work with Oracle SQL (18c).

Insert the result of a query

The result of a select statement can be inserted into a table:
INSERT INTO target_table
  SELECT …
  FROM   …
;

INSERT OR IGNORE

create table tq84_t(id integer primary key, val text unique);

insert or ignore into tq84_t (val) values ('foo');
insert or ignore into tq84_t (val) values ('bar');
insert or ignore into tq84_t (val) values ('foo');
insert or ignore into tq84_t (val) values ('baz');

select * from tq84_t;
insert or ignore is equivalent to insert on conflict ignore.

See also

A trigger allows to specify a sequence of actions to be executed when one or more records are inserted into a table.
DML statements

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1788416281, '216.73.217.21', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL/DML/insert/index(81): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78