Quiz Section 1 �~SQLite intro
Meet Your TAs
Kushagra Bhatia
* please call me Kush
Hongyi Ji
Resources
https://sites.google.com/cs.washington.edu/cse414-22au/
https://edstem.org/us/courses/29763/discussion/
Review: Database and DBMS
4
Review: Database and DBMS
5
What is SQL (Structured Query Language) ?
6
SQLite: What is it?
7
SQLite Installation
8
SQLite Installation
Linux - Open a terminal, then run the command:
sudo apt-get install sqlite3
Mac -
brew install sqlite3
9
SQLite Installation (con’t)
Windows -
Video walkthrough: https://www.youtube.com/watch?v=XA3w8tQnYCA&t=2s
10
Running SQLite
Linux/Mac - Open a terminal, then run the command:
sqlite3 [database]
where “database” is the name of the database
Windows -
11
SQLite: Basic SQL Statements
CREATE TABLE: creates a new table
[ex] CREATE TABLE tableName (columnName int, ... );
12
SQLite: Basic SQL Statements
Primary Key constraint
A primary key is a field / set of fields in a table which uniquely identifies the each rows/records in a database table. Primary keys must contain unique values. A primary key column cannot have NULL values.
A table can have only one primary key, which may consist of single or multiple fields.
[ex] CREATE TABLE tableName (columnName int PRIMARY KEY, ... );
[ex] CREATE TABLE tableName (columnName int, ... , PRIMARY KEY (col1, col2,..));
13
SQLite: Basic SQL Statements
INSERT INTO: inserts new data into table
[ex] INSERT INTO tableName VALUES (value1, …); *Insert value for each column
[ex] INSERT INTO table (column1,column2 ,..) VALUES( value1,...); *Insert value for specific columns
[ex] INSERT INTO table (column1,column2 ,..) VALUES ( value1,...), (value1’,..), (value1’’,...);
*Insert multiple rows
14
SQLite: Basic SQL Statements
SELECT: gets existing data from table
[ex] SELECT columnName,.. FROM tableName;
[ex] SELECT * FROM tableName;
[ex] SELECT columnName,.. FROM tableName WHERE rowFilterRule;
15
Commands for making changes
UPDATE: updates data in table
[ex] UPDATE tableName
SET newValueForColumn(s)
WHERE conditionToSearchRow(s);
16
Commands for making changes
DELETE: deletes data in table
[ex] DELETE FROM tableName
WHERE conditionToSearchRow(s);
DROP: drops a table from the database
[ex] DROP TABLE tableName;
17
Commands for Altering a table
ALTER: can have different applications
[ex] ALTER TABLE existing_table RENAME TO new_table;
[ex] ALTER TABLE table_name ADD/DROP COLUMN column_name;
[ex] ALTER TABLE table_name RENAME COLUMN current_name TO new_name;
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
Multiple Tables
It has to be one of the values contained in the parent table’s primary key.�
20
More SQL
21
SQLite: Special Commands
.help - list other . Commands
.header on/off - show/hide column headers in query results
.databases- shows the database we are in along with the permissions
.tables- shows list of tables
.open- open a database
.mode [mode type] - change how to separate the columns in each row/tuple (for better formatting)
Mode type examples: csv, tabs, line, column
.show - lists all display options
22
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!
24
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!