Hello World! � ~SQLite intro
CSE 414 Winter 2022
Section 1 AD/BD
2022-01-06
Aaditya Desai
Snigdha Goel
Introductions
Announcements
DB Review & Using SQLite
6
Review: Database and DBMS
7
Review: Database and DBMS
8
SQL (Structural Query Language)
9
SQLite: What is it?
12
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
13
SQLite: Basic SQL Statements
CREATE TABLE: creates a new table
[ex] CREATE TABLE tableName (columnName int, ... );
14
SQLite: Basic SQL Statements
INSERT INTO: inserts new data into table
[ex] INSERT INTO tableName VALUES (value1, …);
[ex] INSERT INTO tableName
VALUES (a1, b1, c1, …), (a2, b2, c2, …), … ;
15
SQLite: Basic SQL Statements
SELECT: gets existing data from table
[ex] SELECT columnName FROM tableName;
16
SQLite: Basic SQL Statements
UPDATE: updates data in table
[ex] UPDATE tableName
SET tableName.attributeA = “abc”
WHERE [condition];
17
SQLite: Basic SQL Statements
DELETE: deletes data in table
[ex] DELETE FROM tableName
WHERE [condition];
18
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 -
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
Payroll Demo
CREATE TABLE Payroll (
UserID int primary key,
Name text,
Job text,
Salary int
);
INSERT INTO Payroll VALUES
(123, 'Jack', 'TA', 50000),
(345, 'Allison', 'TA', 60000),
(567, 'Magda', 'Prof', 90000),
(789, 'Dan', 'Prof', 100000);
CREATE TABLE Regist(UserID int, Car text);
INSERT INTO Regist VALUES
(123, 'Charger'),
(567, 'Civic'),
(567, 'Pinto');
27
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!