Insert multiple rows in a single SQL query

SQL

The following example uses ipython-sql. To install:pip install ipython-sql

%sql is a Jupyter magic command and can be ignored when not using Jupyter notebooks.

Configure SQL for Jupyter notebook

#Load sql
%load_ext sql
#connect to sqlite
%sql sqlite://

Create a table

%%sql CREATE TABLE players (first_name, last_name, age);

Insert multiple rows of records into table using a single SQL query

%%sql  INSERT INTO players (first_name, last_name, age) VALUES  ('Lebron', 'James', 33),  ('Steph', 'Curry', 30);

Select all records from our table 'players', to confirm we inserted rows

%%sql  --Select all records from our table 'players', to confirm we inserted rows  SELECT * FROM players
first_name last_name age
Lebron James 33
Steph Curry 30