Ex01-Quick Start
Ex01-Quick Start
ipynb - Colab
%load_ext sql
%sql sqlite:///data/writers.db3
u'Connected: @data/writers.db3'
It is now time to create one using a standard SQL command – CREATE TABLE. If the table already existed in the database, an error will pop up.
In addition, we set PRIMARY KEY on USERID to prevent from inserting duplicate writers into the table.
%%sql sqlite://
CREATE TABLE writer(
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
USERID int NOT NULL UNIQUE,
PRIMARY KEY (USERID)
);
Done.
[]
%%sql sqlite://
INSERT INTO writer VALUES ('William', 'Shakespeare', 1616);
INSERT INTO writer VALUES ('Lin', 'Han', 1996);
INSERT INTO writer VALUES ('Peter', 'Brecht', 1978);
1 rows affected.
1 rows affected.
1 rows affected.
[]
we can put the query result into a variable such as the following sqlres.
https://colab.research.google.com/drive/1KvBxczp18llk_wTkEii4PseMSRNqAJya#printMode=true 1/2
7/25/24, 4:30 PM ex01-Quick Start.ipynb - Colab
* sqlite:///data/writers.db3
Done.
FirstName LastName USERID
William Shakespeare 1616
Lin Han 1996
Peter Brecht 1978
You also can select the specific colummns using their names just like:
* sqlite:///data/writers.db3
Done.
FirstName LastName
William Shakespeare
Lin Han
Peter Brecht
https://colab.research.google.com/drive/1KvBxczp18llk_wTkEii4PseMSRNqAJya#printMode=true 2/2