Hello World! � ~SQLite intro
CSE 414, Autumn '24
Section 1
9/26/24
David Cao (he/him)
Derek Zhu (he/him)
Ice Breakers
Let's get to know each other! Please share...
Announcements
5
Review: Database and DBMS
6
Review: Database and DBMS
7
SQL (Structured Query Language)
8
SQLite: What is it?
9
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
10
SQLite: Basic SQL Statements
CREATE TABLE: creates a new table
[ex] CREATE TABLE tableName (columnName int, ... );
11
SQLite: Basic SQL Statements
INSERT INTO: inserts new data into table
[ex] INSERT INTO tableName VALUES (value1, …);
12
SQLite: Basic SQL Statements
SELECT: gets existing data from table
[ex] SELECT columnName FROM tableName;
13
SQLite: Basic SQL Statements
UPDATE: updates data in table
[ex] UPDATE tableName
SET ….
WHERE [condition];
14
SQLite: Basic SQL Statements
DELETE: deletes data in table
[ex] DELETE FROM tableName
WHERE [condition];
15
SQLite: Basic SQL Statements
ALTER: modify an existing table’s attributes/characteristics
[ex] ALTER TABLE tableName
ADD COLUMN columnName columnDatatype;
[ex] ALTER TABLE tableName DROP COLUMN columnName;
(Note: SQLite does not support dropping an attribute for versions prior to 3.35.5)
[ex] ALTER TABLE oldName RENAME TO newName;
16
What if we want to add more data?
Answer: Create another table!
SQL Foreign Keys
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.
19
More SQL (For Reference)
20
SQLite Installation
21
SQLite Installation
Linux - Open a terminal, then run the command:
sudo apt-get install sqlite3
Mac -
brew install sqlite3
22
SQLite Installation (con’t)
Windows -
Video walkthrough: https://www.youtube.com/watch?v=XA3w8tQnYCA&t=2s
23
Running SQLite
Linux/Mac - Open a terminal, then run the command:
sqlite3 [database]
where “database” is the name of the database
Windows -
24
SQL Demo!
25
26
Didn’t understand everything or having trouble with SQLite install? 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!