Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

SQLite Cheat Sheet

by fetttobse (fetttobse) via cheatography.com/27664/cs/8070/

Basics Alter Tables Constr​aints

sqlite Will create a new The ALTER TABLE function is limited in PRIMARY KEY Sets column as primary key.
filena​me.db database SQLite. The constr​aints NOT NULL
You can either rename the table with: and UNIQUE will be set

Create Tables
ALTER TABLE tablename RENAME TO automa​tic​ally.
newtab​lename
NOT NULL Prevents the column from
CREATE TABLE name (
Or add a new column with: empty values (null).
colname type constr​aints,
ALTER TABLE tablename ADD COLUMN
colname type constr​aints UNIQUE Each value in the column has
column​def​intion
to be unique.
)
It is not possible to change column defini​tions of
This will create a new table. For types and existing tables. INTEGER PRIMARY KEY s will automa​tically
constr​aints look right. become the ROWID and therefore will be

Drop Table automa​tically increm​ented. This column can be


Insert Data accessed as ROWID, OID, _ROWID_ or the
DROP TABLE tablename
column name.
INSERT INTO tablename (column2,
column4)
Select from Table
VALUES
SELECT table1.co​lumn1,
(data1, data2),
table.2​co​lumn2,
(data3, data4);
FROM table1, table2
You don't have to fill every column of the table.
WHERE expres​sion
It is often useful to leave out columns with
primary keys or default value insertion. ORDER BY table1.co​lumn1 order
The ORDER BY is optional, possible ways to
Update Tables order are ASC (ascen​ding) and DESC
(desce​nding).
UPDATE tablename
SET column5 = value5
Data Types
WHERE expres​sion
This will update the given column with the given NULL null value
value, where the expression evaluates true INTEGER Integer value
(usually specific primary key).
REAL 8-byte floating point number

TEXT Text with UTF encoding

BLOB Blob-Data (stored like input)

BOOLEAN Will be stored as Integer (0 for


false, 1 for true)

By fetttobse (fetttobse) Published 4th May, 2016. Sponsored by CrosswordCheats.com


cheatography.com/fetttobse/ Last updated 4th May, 2016. Learn to solve cryptic crosswords!
blog.fetttobse.de Page 1 of 1. http://crosswordcheats.com

You might also like