SlideShare a Scribd company logo
1 of 97
Download to read offline
MODULE 5: SQL AND SQLITE
SQL and Scripting Training
(C) 2020-2021 Highervista, LLC 1
2
TOPICS
Types of RDBMS systems
Getting started with a database
project (e.g., Capstone)
SQL Concepts (DDL and DML
starter)
DDL Starter
DML Starter
Introducing SQLite
Setting up the SQLite
Environment
DB Browser for SQLite
Simple Commands in the SQLite
CLI
Preview Day 5 Afternoon
Activities
TYPES OF RDBMS SYSTEMS SQL and Scripting
Training
4
A SAMPLING OF RDBMS SYSTEMS
5
GUI, SLI, OTHER
Some RDBMSs are primarily graphic
by design (GUI) – Think Microsoft
Access.
Most have a command-line interface
too (CLI).
SQLite is an RDBMS that has
command-line interface (CLI). It also
has a browser option (SQLite Browser
and other browser-like tools available).
6
DATABASE MANAGEMENT SYSTEM/SQL
RDBMS SQL Engine
SQLite SQL – 1 file .db
MySQL SQL – complex file system
PostgreSQL SQL – complex file system
Oracle SQL – complex file system
SQL CONCEPTS (DDL AND DML
STARTER)
SQL and Scripting Training
8
TYPES OF SQL COMMANDS
9
DDL, DML, AND DCL
Category Description Examples
Data definition language (DDL) A series of commands used to change
the way data is stored in the database
and/or alter its structure.
ALTER
COMMENT
CREATE
DROP
RENAME
TRUNCATE
Data manipulation language
(DML)
A series of commands used to add
and/or manipulate data within the
existing database schema.
INSERT
UPDATE
DELETE
Data control language (DCL) Two commands used to allow or
remove access and/or privileges to the
database
GRANT
REVOKE
10
A NOTE ON DATABASE VIEWS
A VIEW is a virtual table displaying the
results of an SQL statement.
It can contain data from more than one table
and runs when it′s accessed, so the data
displayed is current.
It’s useful if you want a user to be able to see
specific data without having access to the
entire database.
11
CLI VS. GUI
CLI: All commands (DDL and DML) can be
entered into the command line. Tedious.
GUI: We’ll use DB Browser for SQLite. As you
make selections in the user interface, you can
see the DDL/DML be created.
12
COURSE FOCUS WITH SQLITE
DDL (like CREATE database, etc.)
DML (like SELECT commands, etc.)
Views (restrict user’s view of the database)
SQLite ‘.dot’ commands (‘support’ commands in
SQLite, similar to other database packages)
DDL—STARTER
SQL and Scripting
Training
14
DATA DEFINITION LANGUAGE (DDL)
• You can either create DDL ″by hand″
(text) or, for some ER design tools,
the DDL can be automatically
created from the design.
• Keep in mind that a complete Data
Dictionary can serve as a basis for
creating tables in the database.
• There are other DDL commands that
will assist you in creating the tables
and altering the table structure.
15
DDL STATEMENTS
• CREATE: Used to create the database or its objects (like table,
index, function, views, store procedure and triggers).
• DROP: Used to delete objects from the database.
• ALTER: Used to alter the structure of the database.
• TRUNCATE: Used to remove all records from a table, including
all spaces allocated for the records are removed.
• COMMENT: Used to add comments to the data dictionary.
• RENAME: Used to rename an object existing in the database.
(Note: Command varies based on RDBMS.)
16
SQL DDL CREATE
17
SQL DDL DROP
18
SQL DDL RENAME (YOU′LL USE DROP
AND CREATE)
DML—STARTER
SQL and Scripting
Training
20
DATA MANIPULATION LANGUAGE (DML)
• SELECT – Look for (query)
• INSERT – Insert into a table
UPDATE – Update existing info in a table
• DELETE – Delete existing info in a table
21
QUERY, STATEMENT, AND CLAUSE
A query is a request (a question) that returns information from the
database.
An SQL statement is any valid piece of SQL code that is executed by
the SQL engine.
A clause is a subsection of a query containing at least one keyword and
relevant information needed by the query (clause is a portion of a
query).
22
SQL DML SELECT
Words in ALL CAPS are SQL
keywords.
A query can contain multiple
clauses, each starting with a
keyword.
23
SQL DML SELECT
24
SQL DML INSERT INTO (2 METHODS)
25
SQL DML INSERT INTO (METHOD 1)
26
SQL DML INSERT INTO (METHOD 2)
27
SQL DML UPDATE
28
SQL DML UPDATE (INITIAL TABLE)
29
SQL DML UPDATE (UPDATED TABLE)
30
SQL DML DELETE
31
SQL DML DELETE (SINGLE ROW OR MULTIPLE
ROWS)
32
REVIEW OF SQL CONCEPTS
A table is a two-dimensional grid of rows and columns that contain data.
Logical and Physical database terms include
­ table (physical) = entity (logical)
­ field (physical) = attribute (logical)
A database record is a row in a table or multiple rows in a table (with a
unique primary key).
Data can exist as a variety of different data types, such as strings of text,
numbers, or special characters.
Metadata describes the nature and format of the data, including any
minimum/maximum character length or required numbers, letters, or special
characters.
33
REVIEW OF SQL CONCEPTS
Relational databases can contain many tables.
Each table in a relational database should have a primary
key that serves as a unique identifier for a row in a given
table.
A foreign key is any column in a table that exists as a primary
key in another table.
The relationship between tables and their primary and foreign
keys is called a database schema.
A database schema can be shown visually by an ERD (Entity
Relationship Diagram), which serves as a blueprint for a
database.
34
REVIEW OF SQL CONCEPTS
There are a variety of relational database (RDBMS)
products, including the Oracle database, Microsoft
SQL Server, MySQL, IBM DB2, and SQLite. While
they may differ somewhat in their interface, the
fundamental SQL engine is essentially the same (not
including extensions).
The SELECT keyword is the most common
SQL command used in SQL queries.
SQL statements can contain multiple clauses
that use different SQL keywords.
INTRODUCING SQLITE SQL and Scripting
Training
36
SQLITE INTRODUCTION
SQLite is the most popular SQL engine in
the world.
This section of the course includes hands-
on, real-world problem solving using
­ SQLite (the CLI portion)
­ SQLite (the GUI portion)
37
USE CASE OF SQLITE DATABASE
SQLite is likely used more than all other database
engines combined. It is found in
•Every Android device
•Every iPhone and iOS device
•Every Mac
•Every Windows10 machine
•Every Firefox, Chrome, and Safari web browser
•Every instance of Skype
38
FEATURES OF SQLITE
•SQLite does not require a separate server
process or system (serverless).
•SQLite comes with zero-configuration, so
no setup or administration are needed.
•A complete SQLite database is stored in a
single cross-platform disk file.
•SQLite is self-contained, which means no
external dependencies.
SETTING UP THE SQLITE
ENVIRONMENT
SQL and Scripting
Training
40
SQLITE DOWNLOAD PAGE
https://www.sqlite.org/download.html
41
GAINING ACCESS TO SQLITE
Using SQLite, users can create file-based databases that can be
transported across machines, platforms, etc.
The only thing needed to view or edit these databases is the
SQLite command line program (downloads from SQLite website), or
another tool capable of communicating with SQLite (SQLite
browser)
DB BROWSER FOR SQLITE SQL and Scripting
Training
43
DB BROWSER FOR SQLITE
https://sqlitebrowser.org
44
OPEN
Once downloaded, open
the DB Browser for
SQLite. (Consider a
shortcut for easy access.)
45
CREATE A DATABASE USING DB BROWSER
With the DB Browser,
create a new database.
Create a database for
the Capstone, with your
initials.
For example, I’ve
created a database
named
RM_AWS_CAPSTONE.
46
CREATE A DATABASE USING DB BROWSER
Since SQLite is one database
file, it requires at least 1 table.
Add TestTable (Table).
Add a field Test_id, INTEGER,
PK (Primary Key).
Add a field Test_Desc, TEXT.
Notice the SQL commands
populated in the bottom pane.
47
DB CREATED WITH 1 TABLE: LOOK AT
RESULTS
COMMANDS IN THE SQLITE CLI:
INTERACTIVE
SQL and Scripting
Training
49
STARTING WITH AN ERD (CROW’S FOOT
ERD)
50
TASK: CREATE A DATABASE WITH 2
TABLES
Follow along.
51
CREATE A DATABASE
Open terminal window and enter
sqlite3 college.db
This starts SQLite and opens college.db
SQLite creates college.db, if not found
52
CREATE A TABLE: STUDENT
Note: Commands are not case sensitive. I will use UPPER CASE for
commands/reserved words and lower case for fields.
Note: commands are separated by commas and a line ends with ;
53
CREATE A TABLE: STUDENT
When there isn’t an error, sqlite prompts for another line.
For this table, four field names are identified (in lower case), as well as
the data type for each field. Commas separate the commands for each
field.
The entire SQL command ends with a ;
54
CREATE A SECOND TABLE: COURSE
55
SQLITE DOT OR SHELL COMMANDS:
.TABLES
SQLite comes with a handful of ′dot′ commands (aka shell commands)
Dot or shell commands allow you to control the SQLite dbms environment (more on these later)
Our first dot or shell command: .tables
The .tables command identifies the tables within the database. The example includes two tables:
­ course
­ student
56
INSERTING VALUES INTO TABLES: STUDENT
AND INSTRUCTOR
The student and course tables do not have any data.
To insert data into both student and course tables:
57
NOTES ON INSERTING
Remember that text can be anything. You need to identify the text by enclosing it in
single or double quotes.
Note: End a SQL command with a semicolon.
Any dot commands are NOT SQL commands, so they do not need a semicolon.
58
SEE WHAT’S IN EACH TABLE: SELECT
• Select is a query (question) you ask SQL.
• Provide a table name after FROM.
• * means ″ALL″
• Two selects (with select *) reveal data in the student and course table
59
SQL SELECT SPECIFYING COLUMNS (FIELDS)
60
SECOND SHELL COMMAND: .HEADERS ON OR
.HEADERS OFF
The shell command .headers allows you to turn headers on or off.
The headers are the column (or field) names in the table.
61
INSERTING DATA INTO KNOWN FIELDS
In the previous insertion, there were values for each column in the
table.
What if you don’t have values for each field? (Example: no address
for student_id 77)
Solution:
62
OTHER SHELL COMMANDS
At the end of the session .quit or .q
Help list .help
Restarting
­ sqlite3 test.db. << start sqlite and include the college.db name
­ Use .tables to confirm that you have the tables in your database
63
BACKING UP A DATABASE: .BACKUP AND .RESTORE
When in sqlite and your active
database, use .backup to
create a backup of your
database
Create a backup, drop the
tables from the active
database, and restore the
database from the backup
using .restore
64
INSTEAD OF A PIPE, USE CSV
By default, the pipe is used to
separate fields
You can use comma-separated
values (csv) to separate fields
HINT: The csv format is a
common Excel format, so data
can be input from Excel (as a
csv file) into your existing
tables.
65
CLEAN UP REPORTING USING .MODE
WITH HEADERS, TAB, AND COLUMNS
66
WAITING FOR MORE INPUT …
If you get …> after entering a Sequel command …
­ You did not enter ;
­ The SQLite software is waiting for more input.
67
WAITING FOR MORE INPUT …
Make sure you type a semicolon at the end of each SQL command!
The sqlite3 program looks for a semicolon to know when your SQL
command is complete.
If you omit the semicolon, sqlite3 will give you a continuation
prompt and wait for you to enter more text.
This feature allows you to enter SQL commands that span multiple
lines.
68
TASK
Use .schema to examine how each table was constructed.
1. What are the problems with each table?
2. How are these tables associated (linked)?
69
RE-EXAMINING THE ERD
• What needs to be done with
student, course?
o Normalize the relationship.
o Ensure no repeating groups.
o Create an intersection entity
(table).
o Document items in your data
dictionary.
o Craft queries to include all
elements.
SQLITE PRIMARY KEY SQL and Scripting Training
71
PRIMARY KEY
A primary key is a column or group of columns that identifies the
uniqueness of rows in a table.
Each table has one, and only one, primary key.
SQLite allows you to define primary key in two ways…
72
PRIMARY KEY: OPTION ONE
If the primary key has only one column, use the PRIMARY KEY
column constraint to define the primary key as follows:
CREATE TABLE table_name(
column_1 INTEGER NOT NULL PRIMARY KEY,
...
);
73
PRIMARY KEY: OPTION TWO
Second, in case primary key consists of two or more columns, you use the PRIMARY KEY
table constraint to define the primary as shown in the following statement.
CREATE TABLE table_name(
column_1 INTEGER NOT NULL,
column_2 INTEGER NOT NULL,
...
PRIMARY KEY(column_1,column_2,...)
);
74
PRIMARY KEY–NOT NULL
In SQL standard, the primary key column must not contain NULL
values. It means that the primary key column has an implicit NOT
NULL constraint.
However, to make the current version of SQLite compatible with the
earlier version, SQLite allows the primary key column to contain
NULL values.
75
PRIMARY KEY EXAMPLE
CREATE TABLE course (
course_id INTEGER PRIMARY KEY,
course_name TEXT NOT NULL,
course_number INTEGER NOT NULL);
76
PRIMARY KEY EXAMPLE
For tables in which the primary keys consist of more than
one column, you must use the PRIMARY KEY table
constraint to define primary keys.
The following slides show how to create the
student_course intersection table whose primary key
consists of two columns.
RESOLVING M:N
RELATIONSHIPS
SQL and Scripting
Training
78
RESOLVING M:N RELATIONSHIPS
Many-to-many M:N relationships add complexity and confusion to your model and the
application development process.
To resolve M:N relationships, separate the two entities and create two one-to-many 1:M
relationships between them with a third intersection entity.
The intersection entity usually contains attributes from both connecting entities.
79
THE OVERALL MODEL AND SPECIFIC
FOCUS
Note: The model shows the derivation of
composite key on COURSE and STUDENT.
For this example, the composite key is
collapsed into one field.
80
START WITH A LOGICAL M:N
Student ID Student Name Student Address Course ID Course Description
1111 Priya 123 Hilltop Ave CIS111 Introduction to Computers
ENG201 Research Writing
MAT211 Calculus I
2222 Tom 234 Carpentaria Way CIS111 Introduction to Computers
ENG102 English Composition II
MAT101 College Algebra
81
M:N RESOLUTION AND IMPLEMENTATION
INTO SQLITE
• Read relationship both ways to ensure that it meets the business rules.
• For example: One to Many STUDENTs have One to Many COURSEs, and
inversely One to Many COURSEs have One to Many STUDENTs.
• The problem is that a M:N cannot be implemented physically. (It makes sense
logically!)
• Add FK to each entity, which points to back to its associated primary entity.
• ″Normalize″ to remove repeating groups.
• Add any fields to ensure data is ″atomic.″
82
M:N RESOLUTION AND IMPLEMENTATION
INTO SQLITE
• In this version, fields are added to the address to provide more discrete parts of the address
(atomic values), which make it easier to maintain.
• FK is added in each entity to ″tie together″ each entity pair.
• There is still a repeating group of values if a student registers for more than one course.
• Note: Document everything you do in the data dictionary.
83
REPEATING GROUPS OF INFORMATION
REMAIN Student
ID Student Name
Student
Address Course ID Course Description
1111 Priya 123 Hilltop Ave CIS111
Introduction to
Computers
ENG201 Research Writing
MAT211 Calculus I
2222 Tom
234
Carpenteria
Way CIS111
Introduction to
Computers
ENG102 English Composition II
MAT101 College Algebra
84
M:N RESOLUTION AND IMPLEMENTATION
INTO SQLITE
To resolve the M:N relationship, add an intersection entity between STUDENT and COURSE.
• The intersect entity between
STUDENT and COURSE entities,
titled STUDENTCOURSE, contains
the PK attributes from STUDENT and
COURSE.
• The relationship between STUDENT
and STUDENTCOURSE is 1:M.
• The relationship between COURSE
and STUDENTCOURSE is 1:M.
85
M:N RESOLUTION AND IMPLEMENTATION
IN SQLITE
• A STUDENT will have many
STUDENTCOURSEs.
• A COURSE will have many
STUDENTCOURSEs.
86
FOREIGN KEYS AND FK CONSTRAINT
(ENFORCEMENT) • Keep in mind that FKs are an
association from an entity to
another PRIMARY entity.
• The decomposition of M:N
uses FKs to ensure that the
data between entities are
correctly implemented.
• As such, foreign keys must
be implemented with
constraints.
• Constraints enforce that a
foreign key in a given entity
refers to a PRIMARY entity
in an associated entity.
IMPLEMENTING FOREIGN KEYS
IN SQLITE
SQL and Scripting
Training
88
ENFORCING FOREIGN KEYS
SQLite foreign key constraint
enforces the relationships between
related tables.
89
SQLITE FOREIGN KEY CONSTRAINT
SUPPORT
SQLite has supported foreign key
constraint since version 3.6.19.
To check whether your current
version of SQLite supports foreign
key constraints, use:
PRAGMA foreign_keys;
The commands returns 1: enable, 0:
disable
90
SQLITE FOREIGN KEY CONSTRAINT SUPPORT
To enable/disable foreign key
constraint:
PRAGMA foreign_keys = OFF;
PRAGMA foreign_keys – ON:
Note: Ensure that you have foreign key
constraint support turned on.
91
START WITH TWO TABLES: STUDENT AND
STUDENTCOURSE
DROP TABLE student;
CREATE TABLE student (
student_id text PRIMARY KEY,
student_name text NOT NULL,
student_address text NOT NULL,
student_address_city text NOT NULL,
student_address_state_code text NOT NULL,
student_address_zip_code text NOT NULL,
studentcourse_id text NOT NULL,
FOREIGN KEY (studentcourse_id)
REFERENCES studentcourse (studentcourse_id)
);
92
CREATE STUDENT
DROP TABLE student;
CREATE TABLE student (
student_id integer PRIMARY KEY,
student_name text NOT NULL,
student_address text,
course_id text,
FOREIGN KEY (course_id)
REFERENCES studentcourse
(course_id)
);
93
SUMMARY ON PK AND FK
Keep in mind that a ″logical″ model that
contains M:N relationships will need to be
decomposed.
Taking a relationship pair that is indicated by
M:N will result in 3 entities. The two original
entities plus one association (intersection) entity.
Note that the association entity now has the
many side of the relationship (see diagram).
You will work on an exercise that will
solidify many SQL concepts including PK/FK
and the intersection entity.
94
REFERENCES
Draw.io. (2020). Diagrams.net - free flowchart maker and
diagrams online. Retrieved November 23, 2020, from
https://app.diagrams.net/
SQLite Browser. (2020, November 09). DB Browser for SQLite.
Retrieved November 23, 2020, from https://sqlitebrowser.org/
SQLite. (2020). SQLite Main Website. Retrieved November 23,
2020, from https://sqlite.org/index.html
Tutorialspoint. (2020). SQLite Tutorial. Retrieved November 23,
2020, from https://www.tutorialspoint.com/sqlite/index.htm
95
INTRODUCTION
Ron McFarland
Technologist, Educator
Source: Microsoft Images
96
ABOUT THIS COURSE
This course is distributed free. I use several
sources. But importantly, I use the book noted
on the next slide.
If you are using these PowerPoints, please
attribute Highervista, LLC and me (Ron
McFarland). IN ADDITION, please attribute
the author noted on the next slide, as the
author’s textbook provides essential
information for this course.
Source: Microsoft Images
97
INTRODUCTION
This course is offered to you free. HOWEVER, please
purchase the following book, as it is a primary resource for
this course. I do not make any $ from this course or this
book. So, since a handful of good content is derived from the
following text, please support this author!
Title: SQL Quickstart Guide
Author: Walter Shields
Available: Amazon, B&N, and through ClydeBank media
website at:
https://www.clydebankmedia.com/books/programming-
tech/sql-quickstart-guide

More Related Content

What's hot

Sq lite module7
Sq lite module7Sq lite module7
Sq lite module7Highervista
 
Oracle advanced queuing
Oracle advanced queuingOracle advanced queuing
Oracle advanced queuingGurpreet singh
 
Ch 9 S Q L
Ch 9  S Q LCh 9  S Q L
Ch 9 S Q Lguest8fdbdd
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMSonia Pahuja
 
Access tips access and sql part 1 setting the sql scene
Access tips  access and sql part 1  setting the sql sceneAccess tips  access and sql part 1  setting the sql scene
Access tips access and sql part 1 setting the sql scenequest2900
 
Dbms narrative question answers
Dbms narrative question answersDbms narrative question answers
Dbms narrative question answersshakhawat02
 
SetFocus Portfolio
SetFocus PortfolioSetFocus Portfolio
SetFocus PortfolioFrank Stepanski
 
lovely
lovelylovely
lovelylove0323
 
Create table
Create tableCreate table
Create tableNitesh Singh
 
BIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.comBIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.comagathachristie241
 
BIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.comBIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.comKeatonJennings120
 
BIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.comBIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.comagathachristie256
 
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.comBIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.comthomashard72
 
BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
 BIS 245 OUTLET Inspiring Innovation--bis245outlet.com BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
BIS 245 OUTLET Inspiring Innovation--bis245outlet.comwilliamwordsworth45
 

What's hot (20)

Sq lite module7
Sq lite module7Sq lite module7
Sq lite module7
 
12 SQL
12 SQL12 SQL
12 SQL
 
Oracle advanced queuing
Oracle advanced queuingOracle advanced queuing
Oracle advanced queuing
 
Ch 9 S Q L
Ch 9  S Q LCh 9  S Q L
Ch 9 S Q L
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 
Viva voce
Viva voceViva voce
Viva voce
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
The Smartpath Information Systems | BASIC RDBMS CONCEPTS
The Smartpath Information Systems | BASIC RDBMS CONCEPTSThe Smartpath Information Systems | BASIC RDBMS CONCEPTS
The Smartpath Information Systems | BASIC RDBMS CONCEPTS
 
Access tips access and sql part 1 setting the sql scene
Access tips  access and sql part 1  setting the sql sceneAccess tips  access and sql part 1  setting the sql scene
Access tips access and sql part 1 setting the sql scene
 
Dbms narrative question answers
Dbms narrative question answersDbms narrative question answers
Dbms narrative question answers
 
SetFocus Portfolio
SetFocus PortfolioSetFocus Portfolio
SetFocus Portfolio
 
lovely
lovelylovely
lovely
 
Create table
Create tableCreate table
Create table
 
BIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.comBIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.com
 
BIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.comBIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.com
 
BIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.comBIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.com
 
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.comBIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
 
Rdbms concepts
Rdbms conceptsRdbms concepts
Rdbms concepts
 
BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
 BIS 245 OUTLET Inspiring Innovation--bis245outlet.com BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
 

Similar to Sq lite module5

Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Vidyasagar Mundroy
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 
MS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutionsMS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutionsRSolutions
 
Presentation1
Presentation1Presentation1
Presentation1ahsan-1252
 
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptxFayChan8
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro projectARVIND SARDAR
 
android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptxRareDeath
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxKashifManzoorMeo
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptxSheethal Aji Mani
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxQuyVo27
 

Similar to Sq lite module5 (20)

Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)Database Systems - Introduction to SQL (Chapter 3/1)
Database Systems - Introduction to SQL (Chapter 3/1)
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
MySQL intro
MySQL introMySQL intro
MySQL intro
 
MySQL intro
MySQL introMySQL intro
MySQL intro
 
Sqlite
SqliteSqlite
Sqlite
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
Sq lite
Sq liteSq lite
Sq lite
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
MS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutionsMS SQL - Database Programming Concepts by RSolutions
MS SQL - Database Programming Concepts by RSolutions
 
Presentation1
Presentation1Presentation1
Presentation1
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
 
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
20190326165338_ISYS6508-PPT5-W5-S6-R0.pptx
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
SQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptxSQL_SERVER_BASIC_1_Training.pptx
SQL_SERVER_BASIC_1_Training.pptx
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
 

More from Highervista

Sq lite module3
Sq lite module3Sq lite module3
Sq lite module3Highervista
 
Cyber security training using virtual labs 3 cs umuc presentation august 2018
Cyber security training using virtual labs 3 cs umuc presentation august 2018Cyber security training using virtual labs 3 cs umuc presentation august 2018
Cyber security training using virtual labs 3 cs umuc presentation august 2018Highervista
 
Cyber security for manufacturers umuc cadf-ron mcfarland
Cyber security for manufacturers umuc cadf-ron mcfarlandCyber security for manufacturers umuc cadf-ron mcfarland
Cyber security for manufacturers umuc cadf-ron mcfarlandHighervista
 
Intro infosec version 2
Intro infosec version 2Intro infosec version 2
Intro infosec version 2Highervista
 
How to create a maker space v2 ebook
How to create a maker space v2 ebookHow to create a maker space v2 ebook
How to create a maker space v2 ebookHighervista
 
Love and silence v3 scribd slide share
Love and silence v3 scribd slide shareLove and silence v3 scribd slide share
Love and silence v3 scribd slide shareHighervista
 

More from Highervista (6)

Sq lite module3
Sq lite module3Sq lite module3
Sq lite module3
 
Cyber security training using virtual labs 3 cs umuc presentation august 2018
Cyber security training using virtual labs 3 cs umuc presentation august 2018Cyber security training using virtual labs 3 cs umuc presentation august 2018
Cyber security training using virtual labs 3 cs umuc presentation august 2018
 
Cyber security for manufacturers umuc cadf-ron mcfarland
Cyber security for manufacturers umuc cadf-ron mcfarlandCyber security for manufacturers umuc cadf-ron mcfarland
Cyber security for manufacturers umuc cadf-ron mcfarland
 
Intro infosec version 2
Intro infosec version 2Intro infosec version 2
Intro infosec version 2
 
How to create a maker space v2 ebook
How to create a maker space v2 ebookHow to create a maker space v2 ebook
How to create a maker space v2 ebook
 
Love and silence v3 scribd slide share
Love and silence v3 scribd slide shareLove and silence v3 scribd slide share
Love and silence v3 scribd slide share
 

Recently uploaded

2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitivaDiego IvĂĄn Oliveros Acosta
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy LĂłpez
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 

Recently uploaded (20)

Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva2.pdf Ejercicios de programaciĂłn competitiva
2.pdf Ejercicios de programaciĂłn competitiva
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 

Sq lite module5

  • 1. MODULE 5: SQL AND SQLITE SQL and Scripting Training (C) 2020-2021 Highervista, LLC 1
  • 2. 2 TOPICS Types of RDBMS systems Getting started with a database project (e.g., Capstone) SQL Concepts (DDL and DML starter) DDL Starter DML Starter Introducing SQLite Setting up the SQLite Environment DB Browser for SQLite Simple Commands in the SQLite CLI Preview Day 5 Afternoon Activities
  • 3. TYPES OF RDBMS SYSTEMS SQL and Scripting Training
  • 4. 4 A SAMPLING OF RDBMS SYSTEMS
  • 5. 5 GUI, SLI, OTHER Some RDBMSs are primarily graphic by design (GUI) – Think Microsoft Access. Most have a command-line interface too (CLI). SQLite is an RDBMS that has command-line interface (CLI). It also has a browser option (SQLite Browser and other browser-like tools available).
  • 6. 6 DATABASE MANAGEMENT SYSTEM/SQL RDBMS SQL Engine SQLite SQL – 1 file .db MySQL SQL – complex file system PostgreSQL SQL – complex file system Oracle SQL – complex file system
  • 7. SQL CONCEPTS (DDL AND DML STARTER) SQL and Scripting Training
  • 8. 8 TYPES OF SQL COMMANDS
  • 9. 9 DDL, DML, AND DCL Category Description Examples Data definition language (DDL) A series of commands used to change the way data is stored in the database and/or alter its structure. ALTER COMMENT CREATE DROP RENAME TRUNCATE Data manipulation language (DML) A series of commands used to add and/or manipulate data within the existing database schema. INSERT UPDATE DELETE Data control language (DCL) Two commands used to allow or remove access and/or privileges to the database GRANT REVOKE
  • 10. 10 A NOTE ON DATABASE VIEWS A VIEW is a virtual table displaying the results of an SQL statement. It can contain data from more than one table and runs when it′s accessed, so the data displayed is current. It’s useful if you want a user to be able to see specific data without having access to the entire database.
  • 11. 11 CLI VS. GUI CLI: All commands (DDL and DML) can be entered into the command line. Tedious. GUI: We’ll use DB Browser for SQLite. As you make selections in the user interface, you can see the DDL/DML be created.
  • 12. 12 COURSE FOCUS WITH SQLITE DDL (like CREATE database, etc.) DML (like SELECT commands, etc.) Views (restrict user’s view of the database) SQLite ‘.dot’ commands (‘support’ commands in SQLite, similar to other database packages)
  • 14. 14 DATA DEFINITION LANGUAGE (DDL) • You can either create DDL ″by hand″ (text) or, for some ER design tools, the DDL can be automatically created from the design. • Keep in mind that a complete Data Dictionary can serve as a basis for creating tables in the database. • There are other DDL commands that will assist you in creating the tables and altering the table structure.
  • 15. 15 DDL STATEMENTS • CREATE: Used to create the database or its objects (like table, index, function, views, store procedure and triggers). • DROP: Used to delete objects from the database. • ALTER: Used to alter the structure of the database. • TRUNCATE: Used to remove all records from a table, including all spaces allocated for the records are removed. • COMMENT: Used to add comments to the data dictionary. • RENAME: Used to rename an object existing in the database. (Note: Command varies based on RDBMS.)
  • 18. 18 SQL DDL RENAME (YOU′LL USE DROP AND CREATE)
  • 20. 20 DATA MANIPULATION LANGUAGE (DML) • SELECT – Look for (query) • INSERT – Insert into a table UPDATE – Update existing info in a table • DELETE – Delete existing info in a table
  • 21. 21 QUERY, STATEMENT, AND CLAUSE A query is a request (a question) that returns information from the database. An SQL statement is any valid piece of SQL code that is executed by the SQL engine. A clause is a subsection of a query containing at least one keyword and relevant information needed by the query (clause is a portion of a query).
  • 22. 22 SQL DML SELECT Words in ALL CAPS are SQL keywords. A query can contain multiple clauses, each starting with a keyword.
  • 24. 24 SQL DML INSERT INTO (2 METHODS)
  • 25. 25 SQL DML INSERT INTO (METHOD 1)
  • 26. 26 SQL DML INSERT INTO (METHOD 2)
  • 28. 28 SQL DML UPDATE (INITIAL TABLE)
  • 29. 29 SQL DML UPDATE (UPDATED TABLE)
  • 31. 31 SQL DML DELETE (SINGLE ROW OR MULTIPLE ROWS)
  • 32. 32 REVIEW OF SQL CONCEPTS A table is a two-dimensional grid of rows and columns that contain data. Logical and Physical database terms include ­ table (physical) = entity (logical) ­ field (physical) = attribute (logical) A database record is a row in a table or multiple rows in a table (with a unique primary key). Data can exist as a variety of different data types, such as strings of text, numbers, or special characters. Metadata describes the nature and format of the data, including any minimum/maximum character length or required numbers, letters, or special characters.
  • 33. 33 REVIEW OF SQL CONCEPTS Relational databases can contain many tables. Each table in a relational database should have a primary key that serves as a unique identifier for a row in a given table. A foreign key is any column in a table that exists as a primary key in another table. The relationship between tables and their primary and foreign keys is called a database schema. A database schema can be shown visually by an ERD (Entity Relationship Diagram), which serves as a blueprint for a database.
  • 34. 34 REVIEW OF SQL CONCEPTS There are a variety of relational database (RDBMS) products, including the Oracle database, Microsoft SQL Server, MySQL, IBM DB2, and SQLite. While they may differ somewhat in their interface, the fundamental SQL engine is essentially the same (not including extensions). The SELECT keyword is the most common SQL command used in SQL queries. SQL statements can contain multiple clauses that use different SQL keywords.
  • 35. INTRODUCING SQLITE SQL and Scripting Training
  • 36. 36 SQLITE INTRODUCTION SQLite is the most popular SQL engine in the world. This section of the course includes hands- on, real-world problem solving using ­ SQLite (the CLI portion) ­ SQLite (the GUI portion)
  • 37. 37 USE CASE OF SQLITE DATABASE SQLite is likely used more than all other database engines combined. It is found in •Every Android device •Every iPhone and iOS device •Every Mac •Every Windows10 machine •Every Firefox, Chrome, and Safari web browser •Every instance of Skype
  • 38. 38 FEATURES OF SQLITE •SQLite does not require a separate server process or system (serverless). •SQLite comes with zero-configuration, so no setup or administration are needed. •A complete SQLite database is stored in a single cross-platform disk file. •SQLite is self-contained, which means no external dependencies.
  • 39. SETTING UP THE SQLITE ENVIRONMENT SQL and Scripting Training
  • 41. 41 GAINING ACCESS TO SQLITE Using SQLite, users can create file-based databases that can be transported across machines, platforms, etc. The only thing needed to view or edit these databases is the SQLite command line program (downloads from SQLite website), or another tool capable of communicating with SQLite (SQLite browser)
  • 42. DB BROWSER FOR SQLITE SQL and Scripting Training
  • 43. 43 DB BROWSER FOR SQLITE https://sqlitebrowser.org
  • 44. 44 OPEN Once downloaded, open the DB Browser for SQLite. (Consider a shortcut for easy access.)
  • 45. 45 CREATE A DATABASE USING DB BROWSER With the DB Browser, create a new database. Create a database for the Capstone, with your initials. For example, I’ve created a database named RM_AWS_CAPSTONE.
  • 46. 46 CREATE A DATABASE USING DB BROWSER Since SQLite is one database file, it requires at least 1 table. Add TestTable (Table). Add a field Test_id, INTEGER, PK (Primary Key). Add a field Test_Desc, TEXT. Notice the SQL commands populated in the bottom pane.
  • 47. 47 DB CREATED WITH 1 TABLE: LOOK AT RESULTS
  • 48. COMMANDS IN THE SQLITE CLI: INTERACTIVE SQL and Scripting Training
  • 49. 49 STARTING WITH AN ERD (CROW’S FOOT ERD)
  • 50. 50 TASK: CREATE A DATABASE WITH 2 TABLES Follow along.
  • 51. 51 CREATE A DATABASE Open terminal window and enter sqlite3 college.db This starts SQLite and opens college.db SQLite creates college.db, if not found
  • 52. 52 CREATE A TABLE: STUDENT Note: Commands are not case sensitive. I will use UPPER CASE for commands/reserved words and lower case for fields. Note: commands are separated by commas and a line ends with ;
  • 53. 53 CREATE A TABLE: STUDENT When there isn’t an error, sqlite prompts for another line. For this table, four field names are identified (in lower case), as well as the data type for each field. Commas separate the commands for each field. The entire SQL command ends with a ;
  • 54. 54 CREATE A SECOND TABLE: COURSE
  • 55. 55 SQLITE DOT OR SHELL COMMANDS: .TABLES SQLite comes with a handful of ′dot′ commands (aka shell commands) Dot or shell commands allow you to control the SQLite dbms environment (more on these later) Our first dot or shell command: .tables The .tables command identifies the tables within the database. The example includes two tables: ­ course ­ student
  • 56. 56 INSERTING VALUES INTO TABLES: STUDENT AND INSTRUCTOR The student and course tables do not have any data. To insert data into both student and course tables:
  • 57. 57 NOTES ON INSERTING Remember that text can be anything. You need to identify the text by enclosing it in single or double quotes. Note: End a SQL command with a semicolon. Any dot commands are NOT SQL commands, so they do not need a semicolon.
  • 58. 58 SEE WHAT’S IN EACH TABLE: SELECT • Select is a query (question) you ask SQL. • Provide a table name after FROM. • * means ″ALL″ • Two selects (with select *) reveal data in the student and course table
  • 59. 59 SQL SELECT SPECIFYING COLUMNS (FIELDS)
  • 60. 60 SECOND SHELL COMMAND: .HEADERS ON OR .HEADERS OFF The shell command .headers allows you to turn headers on or off. The headers are the column (or field) names in the table.
  • 61. 61 INSERTING DATA INTO KNOWN FIELDS In the previous insertion, there were values for each column in the table. What if you don’t have values for each field? (Example: no address for student_id 77) Solution:
  • 62. 62 OTHER SHELL COMMANDS At the end of the session .quit or .q Help list .help Restarting ­ sqlite3 test.db. << start sqlite and include the college.db name ­ Use .tables to confirm that you have the tables in your database
  • 63. 63 BACKING UP A DATABASE: .BACKUP AND .RESTORE When in sqlite and your active database, use .backup to create a backup of your database Create a backup, drop the tables from the active database, and restore the database from the backup using .restore
  • 64. 64 INSTEAD OF A PIPE, USE CSV By default, the pipe is used to separate fields You can use comma-separated values (csv) to separate fields HINT: The csv format is a common Excel format, so data can be input from Excel (as a csv file) into your existing tables.
  • 65. 65 CLEAN UP REPORTING USING .MODE WITH HEADERS, TAB, AND COLUMNS
  • 66. 66 WAITING FOR MORE INPUT … If you get …> after entering a Sequel command … ­ You did not enter ; ­ The SQLite software is waiting for more input.
  • 67. 67 WAITING FOR MORE INPUT … Make sure you type a semicolon at the end of each SQL command! The sqlite3 program looks for a semicolon to know when your SQL command is complete. If you omit the semicolon, sqlite3 will give you a continuation prompt and wait for you to enter more text. This feature allows you to enter SQL commands that span multiple lines.
  • 68. 68 TASK Use .schema to examine how each table was constructed. 1. What are the problems with each table? 2. How are these tables associated (linked)?
  • 69. 69 RE-EXAMINING THE ERD • What needs to be done with student, course? o Normalize the relationship. o Ensure no repeating groups. o Create an intersection entity (table). o Document items in your data dictionary. o Craft queries to include all elements.
  • 70. SQLITE PRIMARY KEY SQL and Scripting Training
  • 71. 71 PRIMARY KEY A primary key is a column or group of columns that identifies the uniqueness of rows in a table. Each table has one, and only one, primary key. SQLite allows you to define primary key in two ways…
  • 72. 72 PRIMARY KEY: OPTION ONE If the primary key has only one column, use the PRIMARY KEY column constraint to define the primary key as follows: CREATE TABLE table_name( column_1 INTEGER NOT NULL PRIMARY KEY, ... );
  • 73. 73 PRIMARY KEY: OPTION TWO Second, in case primary key consists of two or more columns, you use the PRIMARY KEY table constraint to define the primary as shown in the following statement. CREATE TABLE table_name( column_1 INTEGER NOT NULL, column_2 INTEGER NOT NULL, ... PRIMARY KEY(column_1,column_2,...) );
  • 74. 74 PRIMARY KEY–NOT NULL In SQL standard, the primary key column must not contain NULL values. It means that the primary key column has an implicit NOT NULL constraint. However, to make the current version of SQLite compatible with the earlier version, SQLite allows the primary key column to contain NULL values.
  • 75. 75 PRIMARY KEY EXAMPLE CREATE TABLE course ( course_id INTEGER PRIMARY KEY, course_name TEXT NOT NULL, course_number INTEGER NOT NULL);
  • 76. 76 PRIMARY KEY EXAMPLE For tables in which the primary keys consist of more than one column, you must use the PRIMARY KEY table constraint to define primary keys. The following slides show how to create the student_course intersection table whose primary key consists of two columns.
  • 78. 78 RESOLVING M:N RELATIONSHIPS Many-to-many M:N relationships add complexity and confusion to your model and the application development process. To resolve M:N relationships, separate the two entities and create two one-to-many 1:M relationships between them with a third intersection entity. The intersection entity usually contains attributes from both connecting entities.
  • 79. 79 THE OVERALL MODEL AND SPECIFIC FOCUS Note: The model shows the derivation of composite key on COURSE and STUDENT. For this example, the composite key is collapsed into one field.
  • 80. 80 START WITH A LOGICAL M:N Student ID Student Name Student Address Course ID Course Description 1111 Priya 123 Hilltop Ave CIS111 Introduction to Computers ENG201 Research Writing MAT211 Calculus I 2222 Tom 234 Carpentaria Way CIS111 Introduction to Computers ENG102 English Composition II MAT101 College Algebra
  • 81. 81 M:N RESOLUTION AND IMPLEMENTATION INTO SQLITE • Read relationship both ways to ensure that it meets the business rules. • For example: One to Many STUDENTs have One to Many COURSEs, and inversely One to Many COURSEs have One to Many STUDENTs. • The problem is that a M:N cannot be implemented physically. (It makes sense logically!) • Add FK to each entity, which points to back to its associated primary entity. • ″Normalize″ to remove repeating groups. • Add any fields to ensure data is ″atomic.″
  • 82. 82 M:N RESOLUTION AND IMPLEMENTATION INTO SQLITE • In this version, fields are added to the address to provide more discrete parts of the address (atomic values), which make it easier to maintain. • FK is added in each entity to ″tie together″ each entity pair. • There is still a repeating group of values if a student registers for more than one course. • Note: Document everything you do in the data dictionary.
  • 83. 83 REPEATING GROUPS OF INFORMATION REMAIN Student ID Student Name Student Address Course ID Course Description 1111 Priya 123 Hilltop Ave CIS111 Introduction to Computers ENG201 Research Writing MAT211 Calculus I 2222 Tom 234 Carpenteria Way CIS111 Introduction to Computers ENG102 English Composition II MAT101 College Algebra
  • 84. 84 M:N RESOLUTION AND IMPLEMENTATION INTO SQLITE To resolve the M:N relationship, add an intersection entity between STUDENT and COURSE. • The intersect entity between STUDENT and COURSE entities, titled STUDENTCOURSE, contains the PK attributes from STUDENT and COURSE. • The relationship between STUDENT and STUDENTCOURSE is 1:M. • The relationship between COURSE and STUDENTCOURSE is 1:M.
  • 85. 85 M:N RESOLUTION AND IMPLEMENTATION IN SQLITE • A STUDENT will have many STUDENTCOURSEs. • A COURSE will have many STUDENTCOURSEs.
  • 86. 86 FOREIGN KEYS AND FK CONSTRAINT (ENFORCEMENT) • Keep in mind that FKs are an association from an entity to another PRIMARY entity. • The decomposition of M:N uses FKs to ensure that the data between entities are correctly implemented. • As such, foreign keys must be implemented with constraints. • Constraints enforce that a foreign key in a given entity refers to a PRIMARY entity in an associated entity.
  • 87. IMPLEMENTING FOREIGN KEYS IN SQLITE SQL and Scripting Training
  • 88. 88 ENFORCING FOREIGN KEYS SQLite foreign key constraint enforces the relationships between related tables.
  • 89. 89 SQLITE FOREIGN KEY CONSTRAINT SUPPORT SQLite has supported foreign key constraint since version 3.6.19. To check whether your current version of SQLite supports foreign key constraints, use: PRAGMA foreign_keys; The commands returns 1: enable, 0: disable
  • 90. 90 SQLITE FOREIGN KEY CONSTRAINT SUPPORT To enable/disable foreign key constraint: PRAGMA foreign_keys = OFF; PRAGMA foreign_keys – ON: Note: Ensure that you have foreign key constraint support turned on.
  • 91. 91 START WITH TWO TABLES: STUDENT AND STUDENTCOURSE DROP TABLE student; CREATE TABLE student ( student_id text PRIMARY KEY, student_name text NOT NULL, student_address text NOT NULL, student_address_city text NOT NULL, student_address_state_code text NOT NULL, student_address_zip_code text NOT NULL, studentcourse_id text NOT NULL, FOREIGN KEY (studentcourse_id) REFERENCES studentcourse (studentcourse_id) );
  • 92. 92 CREATE STUDENT DROP TABLE student; CREATE TABLE student ( student_id integer PRIMARY KEY, student_name text NOT NULL, student_address text, course_id text, FOREIGN KEY (course_id) REFERENCES studentcourse (course_id) );
  • 93. 93 SUMMARY ON PK AND FK Keep in mind that a ″logical″ model that contains M:N relationships will need to be decomposed. Taking a relationship pair that is indicated by M:N will result in 3 entities. The two original entities plus one association (intersection) entity. Note that the association entity now has the many side of the relationship (see diagram). You will work on an exercise that will solidify many SQL concepts including PK/FK and the intersection entity.
  • 94. 94 REFERENCES Draw.io. (2020). Diagrams.net - free flowchart maker and diagrams online. Retrieved November 23, 2020, from https://app.diagrams.net/ SQLite Browser. (2020, November 09). DB Browser for SQLite. Retrieved November 23, 2020, from https://sqlitebrowser.org/ SQLite. (2020). SQLite Main Website. Retrieved November 23, 2020, from https://sqlite.org/index.html Tutorialspoint. (2020). SQLite Tutorial. Retrieved November 23, 2020, from https://www.tutorialspoint.com/sqlite/index.htm
  • 96. 96 ABOUT THIS COURSE This course is distributed free. I use several sources. But importantly, I use the book noted on the next slide. If you are using these PowerPoints, please attribute Highervista, LLC and me (Ron McFarland). IN ADDITION, please attribute the author noted on the next slide, as the author’s textbook provides essential information for this course. Source: Microsoft Images
  • 97. 97 INTRODUCTION This course is offered to you free. HOWEVER, please purchase the following book, as it is a primary resource for this course. I do not make any $ from this course or this book. So, since a handful of good content is derived from the following text, please support this author! Title: SQL Quickstart Guide Author: Walter Shields Available: Amazon, B&N, and through ClydeBank media website at: https://www.clydebankmedia.com/books/programming- tech/sql-quickstart-guide