SlideShare a Scribd company logo
Introduction 4 SQLite


        Stanley Huang
    wenline1001@gmail.com




                            1/20
Agenda
How to install SQLite on Ubuntu
SQLite client samples
SQLite performance tuning and optimization
 tips
FAQ
Reference
Q&A

                                2/20
How to install SQLite on Ubuntu
Use apt-get
      stanley@Stanley-Ubuntu:/etc$ sudo apt-get -y install sqlite3
      Reading package lists... Done
      Building dependency tree
      Reading state information... Done
      Suggested packages:
       sqlite3-doc
      The following NEW packages will be installed:
       sqlite3
      0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
      Need to get 28.3kB of archives.
      After this operation, 119kB of additional disk space will be used.
      Get:1 http://us.archive.ubuntu.com/ubuntu/ lucid/main sqlite3 3.6.22-1 [28.3kB]
      Fetched 28.3kB in 1s (21.6kB/s)
      Selecting previously deselected package sqlite3.
      (Reading database ... 455043 files and directories currently installed.)
      Unpacking sqlite3 (from .../sqlite3_3.6.22-1_amd64.deb) ...
      Processing triggers for man-db ...
      Setting up sqlite3 (3.6.22-1) ...
      stanley@Stanley-Ubuntu:/etc$


                                                                                        3/20
SQLite client samples
$ which sqlite3
/usr/bin/sqlite3
$ sqlite3
sqlite>




                         4/20
.help
sqlite> .help
.backup ?DB? FILE        Backup DB (default "main") to FILE
.bail ON|OFF         Stop after hitting an error. Default OFF
.databases          List names and files of attached databases
.dump ?TABLE? ...       Dump the database in an SQL text format
               If TABLE specified, only dump tables matching
               LIKE pattern TABLE.
.echo ON|OFF          Turn command echo on or off
.exit          Exit this program
.explain ?ON|OFF?       Turn output mode suitable for EXPLAIN on or off.
               With no args, it turns EXPLAIN on.
.genfkey ?OPTIONS? Options are:
               --no-drop: Do not drop old fkey triggers.
               --ignore-errors: Ignore tables with fkey errors
               --exec: Execute generated SQL immediately
              See file tool/genfkey.README in the source
              distribution for further information.

                                                                           5/20
.help (cont.)
.import FILE TABLE Import data from FILE into TABLE
.indices ?TABLE?      Show names of all indices
               If TABLE specified, only show indices for tables
               matching LIKE pattern TABLE.
.load FILE ?ENTRY? Load an extension library
.mode MODE ?TABLE? Set output mode where MODE is one of:
               csv    Comma-separated values
               column Left-aligned columns. (See .width)
               html HTML <table> code
               insert SQL insert statements for TABLE
               line One value per line
               list Values delimited by .separator string
               tabs Tab-separated values
               tcl   TCL list elements

                                                          6/20
.help (cont.)
.output FILENAME        Send output to FILENAME
.prompt MAIN CONTINUE Replace the standard prompts
.quit          Exit this program
.read FILENAME         Execute SQL in FILENAME
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.schema ?TABLE?          Show the CREATE statements
               If TABLE specified, only show tables matching
               LIKE pattern TABLE.
.show            Show the current values for various settings
.tables ?TABLE?       List names of tables
               If TABLE specified, only list tables matching
               LIKE pattern TABLE.



                                                          7/20
Create Databases
$ sqlite3
sqlite> attach database '/tmp/db1' as db1;
sqlite> attach database '/tmp/db2' as db2;
sqlite> .database
seq name               file
--- --------------- ----------------------------------------------------------
0 main
2 db1               /tmp/db1
3 db2               /tmp/db2




                                                                  8/20
Create Tables
sqlite> create table db1.t11 (id int);
sqlite> create table db1.t12 (id int);
sqlite> create table db2.t21 (id int);
sqlite> create table db2.t22 (id int);




                                     9/20
Insert Data
sqlite> insert into db1.t11 values (11);
sqlite> insert into db1.t12 values (12);
sqlite> insert into db2.t21 values (21);
sqlite> insert into db2.t22 values (22);




                                    10/20
Show Tables/Schema
sqlite> .restore db1
sqlite> .tables
t11 t12
sqlite> .restore db2
sqlite> .tables
t21 t22
sqlite> .schema t21
CREATE TABLE t11(id int);


                            11/20
SQLite performance tuning and
        optimization tips
Back it up or lose it!
  File base, easy to backup by cp command.
Always add an anonymous primary key!
PRAGMA cache_size = ?
  Prior SQLite 2.8.6 split into a BTREE with default “1K” size pages, after 2.8.6 default cache size
   is “2K”.
PRAGMA temp_store = 1
  The choices are DEFAULT (0), FILE (1) and MEMORY (2).
PRAGMA synchronous = OFF
  Default SQLite would wait data write to file, when set synchronous “OFF” and process crash,
   the data file might be corrupt.
PRAGMA journal_mode = MEMORY
  Transaction would be fast, but if process crash, data file might be corrupt.
USE TRANSACTION



                                                                            12/20
SQLite performance tuning and
   optimization tips (Cont.)
Create proper index.
  Proper column of indexes.
  Proper number of indexes.
Compare with “create index then insert data” and “insert data then
 create index”
  With mass of data, “insert data then create index” would be faster.
Simplify the database schema
Don't generalize the database schema
Use temporary tables for intermediate result
Avoid using view and sub-queries
Ordering the tables correctly in where clause



                                                            13/20
SQLite performance tuning and
  optimization tips (Cont.)
Optimizing queries
  Use EXPLAIN command
  Temporary tables
  Order subqueries and smaller results returned
   first
  Use LIMIT and OFFSET
  Replace GLOB and LIKE when possible
  USE IN instead of OR


                                     14/20
SQLite performance tuning and
  optimization tips (Cont.)
Reduce data file size
  Compact database
  Recompiling SQLite with different page size
  Compress large data




                                     15/20
FAQ
What datatype does SQLite support?
  SQLite uses dynamic typing. Content could be INTEGER, REAL,
   TEXT, BOLB or NULL
SQLite let me insert a string into a integer column.
  SQLite uses dynamic typing.
Is SQLite threadsafe?
  SQLite is threadsafe.
  Prior to 3.3.1, SQLite could only used in the same thread.
What's the maximum size for varchar?
  SQLite does not enforce the length of a VARCHAR.



                                                    16/20
FAQ (cont.)
Does SQLite support BOLB?
  SQLite 3.0 and later supported.
How to delete columns from existing table?
  Alter table only support “add column” and “rename table”. Else, you need to
    re-create table.
Does SQLite support foreign key?
  As of verson 3.6.19, SQLite supports foreign key constraint.
I deleted lots of data but data file didn't get smaller.
  You need to run “VACUUM” command to shrink it.
  In SQLite 3.1, you could use auto_vacuum pragma to shrink it automatically.
    But not recommanded, because it take a long time to do it.




                                                            17/20
Reference
SQLite Document
http://sqlite.org/docs.html
Pragma of SQLite
http://www.sqlite.org/pragma.html
Limits of SQLite
http://www.sqlite.org/limits.html


                                    18/20
Q&A




      19/20
Thanks




         20/20

More Related Content

What's hot

A brief introduction to SQLite PPT
A brief introduction to SQLite PPTA brief introduction to SQLite PPT
A brief introduction to SQLite PPT
JavaTpoint
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
Gourav Kumar Saini
 
Database
DatabaseDatabase
android sqlite
android sqliteandroid sqlite
android sqlite
Deepa Rani
 
Getting Started with SQLite
Getting Started with SQLiteGetting Started with SQLite
Getting Started with SQLite
Mindfire Solutions
 
Persitance Data with sqlite
Persitance Data with sqlitePersitance Data with sqlite
Persitance Data with sqlite
Arif Huda
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
Khaled Anaqwa
 
Mysql
MysqlMysql
Mysql
Raghu nath
 
Using sqlite database in android with sqlite manager browser add ons
Using sqlite database in android with sqlite manager browser add onsUsing sqlite database in android with sqlite manager browser add ons
Using sqlite database in android with sqlite manager browser add ons
Vincent Clyde
 
Microsoft sql server architecture
Microsoft sql server architectureMicrosoft sql server architecture
Microsoft sql server architecture
Naveen Boda
 
HPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - IntroductionHPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - Introduction
Frans Jongma
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
info_zybotech
 
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles DaroldPGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
Equnix Business Solutions
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101
IDERA Software
 
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERAGeek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
IDERA Software
 
Sql server backup internals
Sql server backup internalsSql server backup internals
Sql server backup internals
Hamid J. Fard
 
Android Database
Android DatabaseAndroid Database
Android Database
Rashad Aliyev
 
Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012
Umar Ali
 
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sadDevelopers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
mCloud
 

What's hot (20)

A brief introduction to SQLite PPT
A brief introduction to SQLite PPTA brief introduction to SQLite PPT
A brief introduction to SQLite PPT
 
SQLite database in android
SQLite database in androidSQLite database in android
SQLite database in android
 
Database
DatabaseDatabase
Database
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Getting Started with SQLite
Getting Started with SQLiteGetting Started with SQLite
Getting Started with SQLite
 
Persitance Data with sqlite
Persitance Data with sqlitePersitance Data with sqlite
Persitance Data with sqlite
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
 
Mysql
MysqlMysql
Mysql
 
Using sqlite database in android with sqlite manager browser add ons
Using sqlite database in android with sqlite manager browser add onsUsing sqlite database in android with sqlite manager browser add ons
Using sqlite database in android with sqlite manager browser add ons
 
Microsoft sql server architecture
Microsoft sql server architectureMicrosoft sql server architecture
Microsoft sql server architecture
 
HPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - IntroductionHPE NonStop SQL WebDBS - Introduction
HPE NonStop SQL WebDBS - Introduction
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
 
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles DaroldPGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
PGConf.ASIA 2019 Bali - A step towards SQL/MED - DATALINK - Gilles Darold
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101
 
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERAGeek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
 
Sql server backup internals
Sql server backup internalsSql server backup internals
Sql server backup internals
 
Android Database
Android DatabaseAndroid Database
Android Database
 
Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012Difference between sql server 2008 and sql server 2012
Difference between sql server 2008 and sql server 2012
 
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sadDevelopers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
 

Viewers also liked

MySQL進階介紹
MySQL進階介紹MySQL進階介紹
MySQL進階介紹
Stanley Huang
 
MySQL入門介紹
MySQL入門介紹MySQL入門介紹
MySQL入門介紹
Stanley Huang
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
Alexey Bovanenko
 
HDMI
HDMIHDMI
Hdmi cables
Hdmi cablesHdmi cables
Hdmi cables
Jasgt Singh
 
SQLite
SQLiteSQLite
SQLite
maymania
 
Sqlite
SqliteSqlite
SQLite
SQLiteSQLite
SQLite
maymania
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
Bilal Amjad
 
Uml - An Overview
Uml - An OverviewUml - An Overview
Uml - An Overview
Raj Thilak S
 
XML - Parte 2
XML - Parte 2XML - Parte 2
XML - Parte 2
Aldo de Queiroz Jr
 
Extreme programming
Extreme programmingExtreme programming
Extreme programming
Chuu Htet Naing
 

Viewers also liked (12)

MySQL進階介紹
MySQL進階介紹MySQL進階介紹
MySQL進階介紹
 
MySQL入門介紹
MySQL入門介紹MySQL入門介紹
MySQL入門介紹
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
 
HDMI
HDMIHDMI
HDMI
 
Hdmi cables
Hdmi cablesHdmi cables
Hdmi cables
 
SQLite
SQLiteSQLite
SQLite
 
Sqlite
SqliteSqlite
Sqlite
 
SQLite
SQLiteSQLite
SQLite
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
Uml - An Overview
Uml - An OverviewUml - An Overview
Uml - An Overview
 
XML - Parte 2
XML - Parte 2XML - Parte 2
XML - Parte 2
 
Extreme programming
Extreme programmingExtreme programming
Extreme programming
 

Similar to Introduction4 SQLite

Sq lite
Sq liteSq lite
sql_bootcamp.pdf
sql_bootcamp.pdfsql_bootcamp.pdf
sql_bootcamp.pdf
John McClane
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
Leerpiny Makouach
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
SiddhantBhardwaj26
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
NIRMAL FELIX
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancements
infusiondev
 
Sq lite module5
Sq lite module5Sq lite module5
Sq lite module5
Highervista
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
Sankhya_Analytics
 
Sqlite3 command reference
Sqlite3 command referenceSqlite3 command reference
Sqlite3 command reference
Raghu nath
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
Oracle 10g
Oracle 10gOracle 10g
Oracle 10g
Svetlin Nakov
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
chaitanya149090
 
Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008
paulguerin
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
Bwsrang Basumatary
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
Balqees Al.Mubarak
 
Cordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITECordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITE
Binu Paul
 
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdfmysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
pradnyamulay
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Rumman Ansari
 
My sql.ppt
My sql.pptMy sql.ppt

Similar to Introduction4 SQLite (20)

Sq lite
Sq liteSq lite
Sq lite
 
sql_bootcamp.pdf
sql_bootcamp.pdfsql_bootcamp.pdf
sql_bootcamp.pdf
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
 
Introduction to Oracle Database.pptx
Introduction to Oracle Database.pptxIntroduction to Oracle Database.pptx
Introduction to Oracle Database.pptx
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
SQL Server 2008 Performance Enhancements
SQL Server 2008 Performance EnhancementsSQL Server 2008 Performance Enhancements
SQL Server 2008 Performance Enhancements
 
Sq lite module5
Sq lite module5Sq lite module5
Sq lite module5
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
Sqlite3 command reference
Sqlite3 command referenceSqlite3 command reference
Sqlite3 command reference
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
Oracle 10g
Oracle 10gOracle 10g
Oracle 10g
 
7. SQL.pptx
7. SQL.pptx7. SQL.pptx
7. SQL.pptx
 
Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
Cordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITECordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITE
 
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdfmysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 

Recently uploaded

Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 

Recently uploaded (20)

Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 

Introduction4 SQLite

  • 1. Introduction 4 SQLite Stanley Huang wenline1001@gmail.com 1/20
  • 2. Agenda How to install SQLite on Ubuntu SQLite client samples SQLite performance tuning and optimization tips FAQ Reference Q&A 2/20
  • 3. How to install SQLite on Ubuntu Use apt-get stanley@Stanley-Ubuntu:/etc$ sudo apt-get -y install sqlite3 Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: sqlite3-doc The following NEW packages will be installed: sqlite3 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 28.3kB of archives. After this operation, 119kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu/ lucid/main sqlite3 3.6.22-1 [28.3kB] Fetched 28.3kB in 1s (21.6kB/s) Selecting previously deselected package sqlite3. (Reading database ... 455043 files and directories currently installed.) Unpacking sqlite3 (from .../sqlite3_3.6.22-1_amd64.deb) ... Processing triggers for man-db ... Setting up sqlite3 (3.6.22-1) ... stanley@Stanley-Ubuntu:/etc$ 3/20
  • 4. SQLite client samples $ which sqlite3 /usr/bin/sqlite3 $ sqlite3 sqlite> 4/20
  • 5. .help sqlite> .help .backup ?DB? FILE Backup DB (default "main") to FILE .bail ON|OFF Stop after hitting an error. Default OFF .databases List names and files of attached databases .dump ?TABLE? ... Dump the database in an SQL text format If TABLE specified, only dump tables matching LIKE pattern TABLE. .echo ON|OFF Turn command echo on or off .exit Exit this program .explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off. With no args, it turns EXPLAIN on. .genfkey ?OPTIONS? Options are: --no-drop: Do not drop old fkey triggers. --ignore-errors: Ignore tables with fkey errors --exec: Execute generated SQL immediately See file tool/genfkey.README in the source distribution for further information. 5/20
  • 6. .help (cont.) .import FILE TABLE Import data from FILE into TABLE .indices ?TABLE? Show names of all indices If TABLE specified, only show indices for tables matching LIKE pattern TABLE. .load FILE ?ENTRY? Load an extension library .mode MODE ?TABLE? Set output mode where MODE is one of: csv Comma-separated values column Left-aligned columns. (See .width) html HTML <table> code insert SQL insert statements for TABLE line One value per line list Values delimited by .separator string tabs Tab-separated values tcl TCL list elements 6/20
  • 7. .help (cont.) .output FILENAME Send output to FILENAME .prompt MAIN CONTINUE Replace the standard prompts .quit Exit this program .read FILENAME Execute SQL in FILENAME .restore ?DB? FILE Restore content of DB (default "main") from FILE .schema ?TABLE? Show the CREATE statements If TABLE specified, only show tables matching LIKE pattern TABLE. .show Show the current values for various settings .tables ?TABLE? List names of tables If TABLE specified, only list tables matching LIKE pattern TABLE. 7/20
  • 8. Create Databases $ sqlite3 sqlite> attach database '/tmp/db1' as db1; sqlite> attach database '/tmp/db2' as db2; sqlite> .database seq name file --- --------------- ---------------------------------------------------------- 0 main 2 db1 /tmp/db1 3 db2 /tmp/db2 8/20
  • 9. Create Tables sqlite> create table db1.t11 (id int); sqlite> create table db1.t12 (id int); sqlite> create table db2.t21 (id int); sqlite> create table db2.t22 (id int); 9/20
  • 10. Insert Data sqlite> insert into db1.t11 values (11); sqlite> insert into db1.t12 values (12); sqlite> insert into db2.t21 values (21); sqlite> insert into db2.t22 values (22); 10/20
  • 11. Show Tables/Schema sqlite> .restore db1 sqlite> .tables t11 t12 sqlite> .restore db2 sqlite> .tables t21 t22 sqlite> .schema t21 CREATE TABLE t11(id int); 11/20
  • 12. SQLite performance tuning and optimization tips Back it up or lose it! File base, easy to backup by cp command. Always add an anonymous primary key! PRAGMA cache_size = ? Prior SQLite 2.8.6 split into a BTREE with default “1K” size pages, after 2.8.6 default cache size is “2K”. PRAGMA temp_store = 1 The choices are DEFAULT (0), FILE (1) and MEMORY (2). PRAGMA synchronous = OFF Default SQLite would wait data write to file, when set synchronous “OFF” and process crash, the data file might be corrupt. PRAGMA journal_mode = MEMORY Transaction would be fast, but if process crash, data file might be corrupt. USE TRANSACTION 12/20
  • 13. SQLite performance tuning and optimization tips (Cont.) Create proper index. Proper column of indexes. Proper number of indexes. Compare with “create index then insert data” and “insert data then create index” With mass of data, “insert data then create index” would be faster. Simplify the database schema Don't generalize the database schema Use temporary tables for intermediate result Avoid using view and sub-queries Ordering the tables correctly in where clause 13/20
  • 14. SQLite performance tuning and optimization tips (Cont.) Optimizing queries Use EXPLAIN command Temporary tables Order subqueries and smaller results returned first Use LIMIT and OFFSET Replace GLOB and LIKE when possible USE IN instead of OR 14/20
  • 15. SQLite performance tuning and optimization tips (Cont.) Reduce data file size Compact database Recompiling SQLite with different page size Compress large data 15/20
  • 16. FAQ What datatype does SQLite support? SQLite uses dynamic typing. Content could be INTEGER, REAL, TEXT, BOLB or NULL SQLite let me insert a string into a integer column. SQLite uses dynamic typing. Is SQLite threadsafe? SQLite is threadsafe. Prior to 3.3.1, SQLite could only used in the same thread. What's the maximum size for varchar? SQLite does not enforce the length of a VARCHAR. 16/20
  • 17. FAQ (cont.) Does SQLite support BOLB? SQLite 3.0 and later supported. How to delete columns from existing table? Alter table only support “add column” and “rename table”. Else, you need to re-create table. Does SQLite support foreign key? As of verson 3.6.19, SQLite supports foreign key constraint. I deleted lots of data but data file didn't get smaller. You need to run “VACUUM” command to shrink it. In SQLite 3.1, you could use auto_vacuum pragma to shrink it automatically. But not recommanded, because it take a long time to do it. 17/20
  • 18. Reference SQLite Document http://sqlite.org/docs.html Pragma of SQLite http://www.sqlite.org/pragma.html Limits of SQLite http://www.sqlite.org/limits.html 18/20
  • 19. Q&A 19/20
  • 20. Thanks 20/20