Hello World! � ~SQLite intro
1
CSE 344
Section 1
TA Intro:
2
TA Intro: [name]
3
Ice Breakers
Let's get to know each other! Please share...
4
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
.headers 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
11
CREATE TABLE tableName (colName INT, ...);
SQLite: Basic SQL Statements
INSERT INTO: inserts new data into table
[ex] INSERT INTO tableName VALUES (value1, …);
12
INSERT INTO tableName VALUES(value1, ...);
SQLite: Basic SQL Statements
SELECT: gets existing data from table
[ex] SELECT columnName FROM tableName;
13
SELECT columnName FROM tableName;
SQLite: Basic SQL Statements
UPDATE: updates data in table
[ex] UPDATE tableName
SET ….
WHERE [condition];
14
UPDATE tableName
SET ...
WHERE [condition];
SQLite: Basic SQL Statements
DELETE: deletes data in table
[ex] DELETE FROM tableName
WHERE [condition];
15
DELETE FROM tableName
WHERE [condition];
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, e.g. on attu)
[ex] ALTER TABLE oldName RENAME TO newName;
16
ALTER TABLE tableName
ADD COLUMN columnName columnDataType;
ALTER TABLE tableName DROP COLUMN columnName;
ALTER TABLE oldName RENAME TO newName;
What if we want to add more data?
17
Answer: Create another table!
SQL Foreign Keys
18
SQLite: Special Operators
DATE operator: lets you work with dates and times; declare as varchar
[ex] SELECT * FROM tableName WHERE dateColumn ='YYYY-MM-DD';
SELECT * FROM tableName WHERE dateColumn < DATE('now', '-1
month');
Other operators: LENGTH(string), SUBSTR(string, start index, end index), etc.
19
SELECT * FROM tableName
WHERE dateColumn = ‘YYYY-MM-DD’;
SELECT * FROM tableName
WHERE dateColumn < DATE(‘now’, ‘-1 month’);
More SQL (For Reference)
20
SQLite Installation
21
SQLite Installation (Linux/Mac)
Linux - Open a terminal, then run the command:
sudo apt-get install sqlite3
Mac - SQLite ships with macOS, so no additional setup is needed
22
SQLite Installation (Windows)
HIGHLY recommended to use attu instead, as SQLite is already installed there.
Windows -
Video walkthrough: https://www.youtube.com/watch?v=XA3w8tQnYCA&t=2s
23
Attu Setup Tips:
You can use VSCode to connect to Attu:
Download the “Remote SSH” extension in VSCode and use it to connect to Attu.
Don’t want to type your password in everytime you go to connect, setup SSH-based connection: https://code.visualstudio.com/docs/remote/troubleshooting#_ssh-tips
24
Connect to attu through VSCode
25
Running SQLite
Linux/Mac - Open a terminal, then run the command:
sqlite3
Windows -
26
Saving your Database
27
SQL Demo!
28