Hello World! � ~SQLite intro
CSE 414, Autumn '24
Section 1 - CB/DB
9/26/24
Your TA
Ice Breakers
Let's get to know each other!
Announcements
4
Review: Database and DBMS
5
Review: Database and DBMS
6
SQL (Structured Query Language)
7
SQLite: What is it?
8
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
9
SQLite: Basic SQL Statements
CREATE TABLE: creates a new table
[ex] CREATE TABLE tableName (columnName int, ... );
10
SQLite: Basic SQL Statements
INSERT INTO: inserts new data into table
[ex] INSERT INTO tableName VALUES (value1, …);
11
SQLite: Basic SQL Statements
SELECT: gets existing data from table
[ex] SELECT columnName FROM tableName;
12
SQLite: Basic SQL Statements
UPDATE: updates data in table
[ex] UPDATE tableName
SET ….
WHERE [condition];
13
SQLite: Basic SQL Statements
DELETE: deletes data in table
[ex] DELETE FROM tableName
WHERE [condition];
14
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;
15
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.
18
More SQL (For Reference)
19
SQLite Installation
20
SQLite Installation
Linux - Open a terminal, then run the command:
sudo apt-get install sqlite3
Mac -
brew install sqlite3
21
SQLite Installation (con’t)
Windows -
Video walkthrough: https://www.youtube.com/watch?v=XA3w8tQnYCA&t=2s
22
Running SQLite
Linux/Mac - Open a terminal, then run the command:
sqlite3 [database]
where “database” is the name of the database
Windows -
23
SQL Demo!
24
25
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!