CSE 344: Section 1
SQL and SQLite
January 6th, 2022
Administrivia
2
Review: Database and DBMS
3
Review: Database and DBMS
4
SQL (Structured Query Language)
5
SQLite: What is it?
6
SQLite Installation
Linux -
sudo apt-get install sqlite3
Mac -
brew install sqlite3
7
SQLite Installation (con’t)
Windows -
8
Running SQLite
Linux/Mac - Open a terminal, then run the command:
sqlite3 [database]
where “database” is the name of the database
Windows -
9
Recommended Text Editors/IDEs
11
Questions on installation �or running SQLite? �Post on Ed Board or visit us during OH!
SQLite: Special Commands
.help - list other . commands
.header on/off - show/hide column headers in query results
.mode [mode type] - change how to separate the columns in each row/tuple (for better formatting)
Mode type examples: csv, tabs, line
.show - lists all display options
12
SQLite: Basic SQL Statements
CREATE TABLE: creates a new table
[ex] CREATE TABLE tableName (columnName int, ... );
13
SQLite: Basic SQL Statements
INSERT INTO: inserts new data into table
[ex single tuple] INSERT INTO tableName VALUES (value1, …);
[ex multiple tuples] INSERT INTO tableName (columnList, …)
VALUES
(value1a, …)
(value2a, …)
…;
14
SQLite: Basic SQL Statements
SELECT: gets existing data from table
[ex] SELECT columnName FROM tableName;
15
SQLite: Basic SQL Statements
UPDATE: updates data in table
[ex] UPDATE tableName
SET ….
WHERE [condition];
16
SQLite: Basic SQL Statements
DELETE: deletes data in table
[ex] DELETE FROM tableName
WHERE [condition];
17
SQLite: Special Operators
DATE operator: lets you work with dates and times; declare as varchar (see hw1 documentation)
[ex] SELECT * FROM tableName WHERE dateColumn ='YYYY-MM-DD';
SELECT * FROM tableName WHERE dateColumn < DATE('now', '-1
month');
Other operators: LIKE, LENGTH(string), SUBSTR(string, start index, end index), etc.
18
More SQL (For Reference)
19
SQL Demo!
20
Google Chrome SQLite demo
https://stackoverflow.com/questions/8936878/where-does-chrome-save-its-sqlite-database-to
Did you know Google Chrome stores some things in a SQLite database file?
Explore on your computer!
22
Didn’t understand everything? That’s okay! This was just a preview.
SQL basics will be explained further in lecture before your homework is due.
*Post on Ed or come to OH with questions!