SlideShare une entreprise Scribd logo
1  sur  26
Proven Database for
IIOT Applications
SQLite
Learn the Music of Database
SESSION #3
Deep Dive into SQLite
www.inforepos.com
Agenda
• Deep Dive SQLite
• DDL (CREATE, ALTER, DROP)
• DCL
• TCL
• More on SQLite
• UNION [ ALL | DINSTINCT ]
• COLLATE
• FUNCTIONS
• AGGREGATE
• DATE and TIME
www.inforepos.com
DDL
SQLite Create, Alter and Drop table
• The SQLite CREATE TABLE command is used to create a new table in an SQLite database.
It is also used to create indexes, views and triggers
Sensor
ID
Sensor
Name
Sensor Type Sensor Usage
TMP01 LM35 Temperature Industrial
TMP02 DHT11 Temperature Regular
TMP03 DHT22 Temperature Regular
• CREATE [TEMP | TEMPORARY]
TABLE table-name (column-def[,
column-def] [,constraint] );
• [ Column Definition –
• name [type] [[CONSTRAINT name]
column-constraint] ]
Eg.
CREATE TABLE TEMPORARY (
sensor_id text(5),
sensor_name text(50));
• sqlite> .tables
CREATE TABLE sensor_list(
sensor_id text(5),
sensor_name text(50));
www.inforepos.com
DDL
SQLite Create, Alter and Drop table
• CREATE TABLE backup_sensor_master AS SELECT * FROM sensor_master ;
• CREATE TABLE backup_sensor_list AS SELECT * FROM sensor_list LIMIT 0;
• ALTER TABLE table_name ADD COLUMN column_name (column_data_type/size);
• | RENAME TO new_table_name;
• ALTER TABLE sensor_list ADD sensor_desc VARCHAR(200);
• ALTER TABLE sensor_list RENAME TO sensor_list_industrial;
• DROP TABLE table_name [, ...] or DROP TABLE [database_name.]table_name [,
...]
• DROP TABLE sensor_list_industrial;
www.inforepos.com
DDL
SQLite Create, Alter and Drop Constraint
• MODIFY COLUMN
• SQLite does not support ALTER TABLE statement to MODIFY a column on an existing table, instead you
need to perform these steps:
• Rename the table to a temporary name
• Create a new table without the NOT NULL constraint
• Copy the content of the old table to the new one
• Remove the old table
• Syntax to MODIFY A COLUMN in a table in SQLite
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
ALTER TABLE table1 RENAME TO _table1_old;
CREATE TABLE table1 ( ( column1 datatype [ NULL | NOT NULL ], column2 datatype [ NULL | NOT NULL ], ... );
INSERT INTO table1 (column1, column2, ... column_n) SELECT column1, column2, ... column_n FROM _table1_old;
COMMIT;
PRAGMA foreign_keys=on;
www.inforepos.com
DDL
SQLite Create, Alter and Drop Constraint
• UNIQUE CONSTRAINT
CREATE TABLE sensor_list1(sid, sname UNIQUE);
CREATE TABLE sensor_list2(sid, sname PRIMARY KEY);
CREATE TABLE sensor_list3(sid, sname);
CREATE UNIQUE INDEX sensor_list_b_uidx ON sensor_list3(sname);
• ALTER & DROP UNIQUE Constraints
• SQLite does not support ALTER TABLE statement to ALTER / DROP unique constraints on
an existing table, instead you need to perform these steps:
• Rename the table to a temporary name
• Create a new table without the NOT NULL constraint
• Copy the content of the old table to the new one
• Remove the old table
• See the below text to ALTER / DROP UNIQUE Constraint
Note : You can not use the ALTER TABLE statement to add/drop the unique constraint. Instead, you must create
a new table with the unique constraint and copy the data into this new table.
www.inforepos.com
DDL
SQLite Create, Alter and Drop Constraint
• FOREIGN KEY CONSTRAINT
CREATE TABLE departments ( department_id INTEGER PRIMARY KEY AUTOINCREMENT, department_name VARCHAR);
CREATE TABLE employees ( employee_id INTEGER PRIMARY KEY AUTOINCREMENT, last_name VARCHAR NOT NULL, first_name VARCHAR,
department_id INTEGER, CONSTRAINT fk_departments FOREIGN KEY (department_id) REFERENCES departments(department_id) );
CREATE TABLE sensor_list1(sid integer CONSTRAINT sl_sid_pk PRIMARY KEY, sname varchar NOT NULL);
CREATE TABLE ihome_sensor_list(ihome_sid, ihome_sname CONSTRAINT fk_sid FOREIGN KEY (ihome_sid) REFERENCES sensor_list1(sid);
• ALTER & DROP FOREIGN KEY Constraints
• SQLite does not support ALTER TABLE statement to ALTER / DROP foreign key constraints on an existing
table, instead you need to perform these steps:
• Rename the table to a temporary name
• Create a new table without the NOT NULL constraint
• Copy the content of the old table to the new one
• Remove the old table
• See the below text to ALTER / DROP UNIQUE Constraint
Note : You can not use the ALTER TABLE statement to add/drop the unique constraint. Instead, you must create a new table with the unique
constraint and copy the data into this new table.
www.inforepos.com
DDL
SQLite Create and Drop Index
• CREATE INDEX index_name ON table_name (column_name);
• CREATE [UNIQUE] INDEX index_name ON table_name ( column_name [, ...] );
• DROP INDEX index_name;
• .indices table_name
• sqlite3> SELECT * FROM sqlite_master WHERE type = 'index';
• Eg.
• CREATE TABLE sensor_list (sensor_id text(5), sensor_name text(50));
• CREATE INDEX sensor_id_idx ON sensor_list (sensor_id);
• CREATE INDEX sensor_id_name_idx ON sensor_list (sensor_id, sensor_name);
www.inforepos.com
DCL
SQLite VACUUM
• The VACUUM command rebuilds the database file, repacking it into a minimal amount of disk
space. The VACUUM command may change the ROWID of entries in tables that do not have an
explicit INTEGER PRIMARY KEY. The VACUUM command only works on the main database. It is
not possible to VACUUM an attached database file.
• The VACUUM command will fail if there is an active transaction. The VACUUM command is a
no-op for in-memory databases. As the VACUUM command rebuilds the database file from
scratch, VACUUM can also be used to modify many database-specific configuration parameters.
Manual VACUUM
Auto-VACCUM
• SQLite Auto-VACUUM does not do the same as VACUUM rather it only moves free pages to the
end of the database thereby reducing the database size. By doing so it can significantly fragment
the database while VACUUM ensures defragmentation. So Auto-VACUUM just keeps the database
small.
• https://sqlite.org/lang_vacuum.html
www.inforepos.com
DCL
SQLite VACUUM
• After DELETE TABLE command to delete all the records, it is recommended to
use VACUUM command to clear unused space.
• (SQLite do not have TRUNCATE TABLE command in SQLite but you can use
SQLite DELETE command to delete complete data from an existing table,
though it is recommended to use DROP TABLE command to drop complete
table and re-create it once again.)
DELETE FROM SENSOR_LIST;
VACUUM;
OR
Retain table structure & then
DROP TABLE table_name;
www.inforepos.com
TCL
SQLite Transaction Control
• A transaction is a unit of work that is performed against a database.
Transactions are units or sequences of work accomplished in a logical order,
whether in a manual fashion by a user or automatically by some sort of a
database program.
• Properties of Transactions (ACID):
• Atomicity: ensures that all operations within the work unit are completed successfully;
otherwise, the transaction is aborted at the point of failure and previous operations are
rolled back to their former state.
• Consistency: ensures that the database properly changes states upon a successfully
committed transaction.
• Isolation: enables transactions to operate independently of and transparent to each other.
• Durability: ensures that the result or effect of a committed transaction persists in case of a
system failure.
www.inforepos.com
TCL
SQLite Transaction Control
• Transaction Control:
• There are the following commands used to control transactions:
• BEGIN TRANSACTION: to start a transaction.
• COMMIT: to save the changes, alternatively you can use END TRANSACTION command.
• ROLLBACK: to rollback the changes.
Transactional control commands are only used with the DML commands INSERT,
UPDATE, and DELETE. They can not be used while creating tables or dropping
them because these operations are automatically committed in the database.
• https://www.sqlite.org/atomiccommit.html
www.inforepos.com
TCL
SQLite Transaction Control
• The BEGIN TRANSACTION Command:
Transactions can be started using BEGIN TRANSACTION or simply BEGIN command. Such transactions usually persist until the next
COMMIT or ROLLBACK command encountered. But a transaction will also ROLLBACK if the database is closed or if an error occurs.
BEGIN;
or
BEGIN TRANSACTION;
• The COMMIT Command:
The COMMIT command is the transactional command used to save changes invoked by a transaction to the database. The COMMIT
command saves all transactions to the database since the last COMMIT or ROLLBACK command.
COMMIT;
or
END TRANSACTION;
• The ROLLBACK Command:
The ROLLBACK command is the transactional command used to undo transactions that have not already been saved to the database. The
ROLLBACK command can only be used to undo transactions since the last COMMIT or ROLLBACK command was issued.
ROLLBACK;
For a detailed example, see notes below.
www.inforepos.com
SQLite UNION | UNION ALL
• UNION operator is used to combine the result from multiple SELECT statements
into a single result set.
• The default characteristic of UNION is, to remove the duplicate rows from the result. The DISTINCT keyword which
is optional does not make any effect, because, by default, it specifies duplicate-row removal. But if we use the
optional keyword ALL, the duplicate-row removal does not happen and the result set includes all matching rows
from all the SELECT statements.
SELECT ...
UNION [ALL | DISTINCT] SELECT ...
[UNION [ALL | DISTINCT] SELECT ...]
Select employee_id, job_id
FROM employees
UNION
Select employee_id,job_id
FROM job_history;
www.inforepos.com
SQLite UNION | UNION ALL
• UNION ALL operator does not eliminate duplicate selected
rows and returns all rows. UNION ALL operator returns all
the rows from both the queries and no duplication
elimination happens.
Compare:
UNION operator returns the combined result from multiple SELECT
statements into a single result set but exclude the duplicate rows
where as the UNION ALL operator avoids the elimination of duplicate
selected rows and returns all rows.
Select employee_id, job_id,department_id
FROM employees
UNION ALL
Select employee_id,job_id,department_id
FROM job_history;
www.inforepos.com
SQLite Collating Sequences
At the time of comparison of two strings, in SQLite, it uses a collating sequence or
collating function to understand which string is greater or whether the two
strings are equal.
SQLite has three built-in collating functions:
• BINARY - Compares string data using memcmp(), regardless of text encoding.
• NOCASE - It is almost same as binary, except the 26 upper case characters of ASCII are folded to their lower case
equivalents before the comparison is performed.
• RTRIM - The same as binary, except that trailing space characters, are ignored.
www.inforepos.com
SQLite Collating Sequences
Text comparison cola=colb is performed using the BINARY collating sequence.
SELECT coln FROM test WHERE cola = colb ORDER BY coln;
Text comparison cola=colb is performed using the RTRIM collating sequence.
SELECT coln FROM test WHERE cola = colb COLLATE rtrim ORDER BY coln;
Text comparison cold=cola is performed using the NOCASE collating sequence.
SELECT coln FROM test WHERE cold = cola ORDER BY coln;
Text comparison cola=cold is performed using the BINARY collating sequence.
SELECT coln FROM test WHERE cola = cold ORDER BY coln;
Text comparison 'pqr'=colc is performed using the RTRIM collating sequence.
SELECT coln FROM test WHERE 'pqr' = colc ORDER BY coln;
Text comparison colc='pqr' is performed using the RTRIM collating sequence.
SELECT coln FROM test WHERE colc = 'pqr' ORDER BY coln;
Grouping is performed using the NOCASE collating sequence (Values 'pqr', 'PQR', and
'Pqr' are placed in the same group).
SELECT count(*) FROM test GROUP BY cold ORDER BY 1;
Grouping is performed using the BINARY collating sequence. 'pqr' and 'PQR' and 'Pqr'
form different groups
SELECT count(*) FROM test GROUP BY (cold || '') ORDER BY 1;
Sorting or column colc is performed using the RTRIM collating sequence.
SELECT coln FROM test ORDER BY colc, coln;
Sorting of (colc||'') is performed using the BINARY collating sequence.
SELECT coln FROM test ORDER BY (colc||''), coln;
Sorting of column colc is performed using the NOCASE collating sequence.
SELECT coln FROM test ORDER BY colc COLLATE NOCASE, coln;
www.inforepos.com
SQLite Functions
abs(X)
changes()
char(X1,X2,...,XN)
coalesce(X,Y,...)
glob(X,Y)
hex(X)
ifnull(X,Y)
instr(X,Y)
last_insert_rowid()
length(X)
like(X,Y)
like(X,Y,Z)
likelihood(X,Y)
likely(X)
load_extension(X)
load_extension(X,Y)
lower(X)
ltrim(X)
ltrim(X,Y)
max(X,Y,...)
min(X,Y,...)
nullif(X,Y)
printf(FORMAT,...)
quote(X)
random()
randomblob(N)
replace(X,Y,Z)
round(X)
round(X,Y)
rtrim(X)
rtrim(X,Y)
soundex(X)
sqlite_compileoption_get(N)
sqlite_compileoption_used(X)
sqlite_source_id()
sqlite_version()
substr(X,Y)
substr(X,Y,Z)
total_changes()
trim(X)
trim(X,Y)
typeof(X)
unicode(X)
upper(X)
zeroblob(N)
www.inforepos.com
SQLite Aggregate Functions
• avg(X)
• count(*)
• count(X)
• group_concat(X)
• group_concat(X,Y)
• max(X)
• min(X)
• sum(X)
• total(X)
Note:
GROUP_CONCAT(X) / GROUP_CONCAT(X, Y)
The group_concat() function returns a string which is the concatenation of all
non-NULL values of X. If parameter Y is present then it is used as the separator
between instances of X. A comma (",") is used as the separator if Y is omitted. The
order of the concatenated elements is arbitrary.
SUM(X) / TOTAL(Y)
The result of total() is always a floating point value. The result of sum() is an
integer value if all non-NULL inputs are integers. If any input to sum() is neither an
integer or a NULL then sum() returns a floating point value which might be an
approximation to the true sum.
COUNT(X) / COUNT(*)
The count(X) function returns a count of the number of times that X is not NULL
in a group. The count(*) function (with no arguments) returns the total number of
rows in the group.
www.inforepos.com
SQLite DATE & TIME functions
• SQLite supports five date and time functions
All above five date and time functions take a time string as an argument. The time string is
followed by zero or more modifiers.
S.No. Function Example
1 date(timestring, modifiers...) This returns the date in this format: YYYY-MM-DD
2 time(timestring, modifiers...) This returns the time as HH:MM:SS
3 datetime(timestring, modifiers...) This returns YYYY-MM-DD HH:MM:SS
4 julianday(timestring, modifiers...)
This returns the number of days since noon in
Greenwich on November 24, 4714 B.C.
5 strftime(timestring, modifiers...)
This returns the date formatted according to the
format string specified as the first argument formatted
as per formatters explained below.
www.inforepos.com
SQLite DATE & TIME functions
• Time Strings: A time string can be in any of the below formats.
• Modifiers: The time string can be followed by zero or more modifiers that will
alter date and/or time returned by any of the above five functions. Modifiers
are applied from left to right and below table shows the available modifiers in
SQLite.
• Formatters: SQLite provides very handy function strftime() to format any date
and time. You can use below substitutions to format your date and time.
www.inforepos.com
SQLite DATE & TIME functions
THANK YOU
For All Queries : info@inforepos.com
Proven Database for
IIOT Applications
SQLite
Learn the Music of Database
IR SQLite Session #3

Contenu connexe

Tendances

Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQLsuriyae1
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsOSSCube
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
Les14[1]Controlling User Access
Les14[1]Controlling User AccessLes14[1]Controlling User Access
Les14[1]Controlling User Accesssiavosh kaviani
 
Boost performance with MySQL 5.1 partitions
Boost performance with MySQL 5.1 partitionsBoost performance with MySQL 5.1 partitions
Boost performance with MySQL 5.1 partitionsGiuseppe Maxia
 
Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statasLouis liu
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objectsSyed Zaid Irshad
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggersrehaniltifat
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesAlex Zaballa
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1Enkitec
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data RedactionAlex Zaballa
 

Tendances (20)

Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
Overview of Oracle database12c for developers
Overview of Oracle database12c for developersOverview of Oracle database12c for developers
Overview of Oracle database12c for developers
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
MySQL Views
MySQL ViewsMySQL Views
MySQL Views
 
Les14[1]Controlling User Access
Les14[1]Controlling User AccessLes14[1]Controlling User Access
Les14[1]Controlling User Access
 
Boost performance with MySQL 5.1 partitions
Boost performance with MySQL 5.1 partitionsBoost performance with MySQL 5.1 partitions
Boost performance with MySQL 5.1 partitions
 
Advanced tips of dbms statas
Advanced tips of dbms statasAdvanced tips of dbms statas
Advanced tips of dbms statas
 
Oracle Database View
Oracle Database ViewOracle Database View
Oracle Database View
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objects
 
8. sql
8. sql8. sql
8. sql
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New Features
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Dbmsmanual
DbmsmanualDbmsmanual
Dbmsmanual
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 
Sequences and indexes
Sequences and indexesSequences and indexes
Sequences and indexes
 

Similaire à IR SQLite Session #3

Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptxSheethal Aji Mani
 
database management system lessonchapter
database management system lessonchapterdatabase management system lessonchapter
database management system lessonchapterMohammedNouh7
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro projectARVIND SARDAR
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
Performance tuning
Performance tuningPerformance tuning
Performance tuningami111
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAiougVizagChapter
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL IISankhya_Analytics
 
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020DmitryLenev
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)Dave Stokes
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2Alex Zaballa
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2Alex Zaballa
 
ii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docxii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docxlakshmi77
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersAlexey Furmanov
 

Similaire à IR SQLite Session #3 (20)

Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
database management system lessonchapter
database management system lessonchapterdatabase management system lessonchapter
database management system lessonchapter
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Sq lite
Sq liteSq lite
Sq lite
 
Dms 22319 micro project
Dms 22319 micro projectDms 22319 micro project
Dms 22319 micro project
 
triggers.pptx
triggers.pptxtriggers.pptx
triggers.pptx
 
Manipulating data
Manipulating dataManipulating data
Manipulating data
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Performance tuning
Performance tuningPerformance tuning
Performance tuning
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
 
SQL
SQLSQL
SQL
 
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
Check Constraints in MySQL 8.0. Presented at pre-FOSDEM MySQL Day 2020
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2
 
DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2DBA Commands and Concepts That Every Developer Should Know - Part 2
DBA Commands and Concepts That Every Developer Should Know - Part 2
 
ii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docxii bcom dbms SQL Commands.docx
ii bcom dbms SQL Commands.docx
 
Lecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML TriggersLecture 4. MS SQL. DML Triggers
Lecture 4. MS SQL. DML Triggers
 

Dernier

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Dernier (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

IR SQLite Session #3

  • 1. Proven Database for IIOT Applications SQLite Learn the Music of Database
  • 2. SESSION #3 Deep Dive into SQLite
  • 3. www.inforepos.com Agenda • Deep Dive SQLite • DDL (CREATE, ALTER, DROP) • DCL • TCL • More on SQLite • UNION [ ALL | DINSTINCT ] • COLLATE • FUNCTIONS • AGGREGATE • DATE and TIME
  • 4. www.inforepos.com DDL SQLite Create, Alter and Drop table • The SQLite CREATE TABLE command is used to create a new table in an SQLite database. It is also used to create indexes, views and triggers Sensor ID Sensor Name Sensor Type Sensor Usage TMP01 LM35 Temperature Industrial TMP02 DHT11 Temperature Regular TMP03 DHT22 Temperature Regular • CREATE [TEMP | TEMPORARY] TABLE table-name (column-def[, column-def] [,constraint] ); • [ Column Definition – • name [type] [[CONSTRAINT name] column-constraint] ] Eg. CREATE TABLE TEMPORARY ( sensor_id text(5), sensor_name text(50)); • sqlite> .tables CREATE TABLE sensor_list( sensor_id text(5), sensor_name text(50));
  • 5. www.inforepos.com DDL SQLite Create, Alter and Drop table • CREATE TABLE backup_sensor_master AS SELECT * FROM sensor_master ; • CREATE TABLE backup_sensor_list AS SELECT * FROM sensor_list LIMIT 0; • ALTER TABLE table_name ADD COLUMN column_name (column_data_type/size); • | RENAME TO new_table_name; • ALTER TABLE sensor_list ADD sensor_desc VARCHAR(200); • ALTER TABLE sensor_list RENAME TO sensor_list_industrial; • DROP TABLE table_name [, ...] or DROP TABLE [database_name.]table_name [, ...] • DROP TABLE sensor_list_industrial;
  • 6. www.inforepos.com DDL SQLite Create, Alter and Drop Constraint • MODIFY COLUMN • SQLite does not support ALTER TABLE statement to MODIFY a column on an existing table, instead you need to perform these steps: • Rename the table to a temporary name • Create a new table without the NOT NULL constraint • Copy the content of the old table to the new one • Remove the old table • Syntax to MODIFY A COLUMN in a table in SQLite PRAGMA foreign_keys=off; BEGIN TRANSACTION; ALTER TABLE table1 RENAME TO _table1_old; CREATE TABLE table1 ( ( column1 datatype [ NULL | NOT NULL ], column2 datatype [ NULL | NOT NULL ], ... ); INSERT INTO table1 (column1, column2, ... column_n) SELECT column1, column2, ... column_n FROM _table1_old; COMMIT; PRAGMA foreign_keys=on;
  • 7. www.inforepos.com DDL SQLite Create, Alter and Drop Constraint • UNIQUE CONSTRAINT CREATE TABLE sensor_list1(sid, sname UNIQUE); CREATE TABLE sensor_list2(sid, sname PRIMARY KEY); CREATE TABLE sensor_list3(sid, sname); CREATE UNIQUE INDEX sensor_list_b_uidx ON sensor_list3(sname); • ALTER & DROP UNIQUE Constraints • SQLite does not support ALTER TABLE statement to ALTER / DROP unique constraints on an existing table, instead you need to perform these steps: • Rename the table to a temporary name • Create a new table without the NOT NULL constraint • Copy the content of the old table to the new one • Remove the old table • See the below text to ALTER / DROP UNIQUE Constraint Note : You can not use the ALTER TABLE statement to add/drop the unique constraint. Instead, you must create a new table with the unique constraint and copy the data into this new table.
  • 8. www.inforepos.com DDL SQLite Create, Alter and Drop Constraint • FOREIGN KEY CONSTRAINT CREATE TABLE departments ( department_id INTEGER PRIMARY KEY AUTOINCREMENT, department_name VARCHAR); CREATE TABLE employees ( employee_id INTEGER PRIMARY KEY AUTOINCREMENT, last_name VARCHAR NOT NULL, first_name VARCHAR, department_id INTEGER, CONSTRAINT fk_departments FOREIGN KEY (department_id) REFERENCES departments(department_id) ); CREATE TABLE sensor_list1(sid integer CONSTRAINT sl_sid_pk PRIMARY KEY, sname varchar NOT NULL); CREATE TABLE ihome_sensor_list(ihome_sid, ihome_sname CONSTRAINT fk_sid FOREIGN KEY (ihome_sid) REFERENCES sensor_list1(sid); • ALTER & DROP FOREIGN KEY Constraints • SQLite does not support ALTER TABLE statement to ALTER / DROP foreign key constraints on an existing table, instead you need to perform these steps: • Rename the table to a temporary name • Create a new table without the NOT NULL constraint • Copy the content of the old table to the new one • Remove the old table • See the below text to ALTER / DROP UNIQUE Constraint Note : You can not use the ALTER TABLE statement to add/drop the unique constraint. Instead, you must create a new table with the unique constraint and copy the data into this new table.
  • 9. www.inforepos.com DDL SQLite Create and Drop Index • CREATE INDEX index_name ON table_name (column_name); • CREATE [UNIQUE] INDEX index_name ON table_name ( column_name [, ...] ); • DROP INDEX index_name; • .indices table_name • sqlite3> SELECT * FROM sqlite_master WHERE type = 'index'; • Eg. • CREATE TABLE sensor_list (sensor_id text(5), sensor_name text(50)); • CREATE INDEX sensor_id_idx ON sensor_list (sensor_id); • CREATE INDEX sensor_id_name_idx ON sensor_list (sensor_id, sensor_name);
  • 10. www.inforepos.com DCL SQLite VACUUM • The VACUUM command rebuilds the database file, repacking it into a minimal amount of disk space. The VACUUM command may change the ROWID of entries in tables that do not have an explicit INTEGER PRIMARY KEY. The VACUUM command only works on the main database. It is not possible to VACUUM an attached database file. • The VACUUM command will fail if there is an active transaction. The VACUUM command is a no-op for in-memory databases. As the VACUUM command rebuilds the database file from scratch, VACUUM can also be used to modify many database-specific configuration parameters. Manual VACUUM Auto-VACCUM • SQLite Auto-VACUUM does not do the same as VACUUM rather it only moves free pages to the end of the database thereby reducing the database size. By doing so it can significantly fragment the database while VACUUM ensures defragmentation. So Auto-VACUUM just keeps the database small. • https://sqlite.org/lang_vacuum.html
  • 11. www.inforepos.com DCL SQLite VACUUM • After DELETE TABLE command to delete all the records, it is recommended to use VACUUM command to clear unused space. • (SQLite do not have TRUNCATE TABLE command in SQLite but you can use SQLite DELETE command to delete complete data from an existing table, though it is recommended to use DROP TABLE command to drop complete table and re-create it once again.) DELETE FROM SENSOR_LIST; VACUUM; OR Retain table structure & then DROP TABLE table_name;
  • 12. www.inforepos.com TCL SQLite Transaction Control • A transaction is a unit of work that is performed against a database. Transactions are units or sequences of work accomplished in a logical order, whether in a manual fashion by a user or automatically by some sort of a database program. • Properties of Transactions (ACID): • Atomicity: ensures that all operations within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure and previous operations are rolled back to their former state. • Consistency: ensures that the database properly changes states upon a successfully committed transaction. • Isolation: enables transactions to operate independently of and transparent to each other. • Durability: ensures that the result or effect of a committed transaction persists in case of a system failure.
  • 13. www.inforepos.com TCL SQLite Transaction Control • Transaction Control: • There are the following commands used to control transactions: • BEGIN TRANSACTION: to start a transaction. • COMMIT: to save the changes, alternatively you can use END TRANSACTION command. • ROLLBACK: to rollback the changes. Transactional control commands are only used with the DML commands INSERT, UPDATE, and DELETE. They can not be used while creating tables or dropping them because these operations are automatically committed in the database. • https://www.sqlite.org/atomiccommit.html
  • 14. www.inforepos.com TCL SQLite Transaction Control • The BEGIN TRANSACTION Command: Transactions can be started using BEGIN TRANSACTION or simply BEGIN command. Such transactions usually persist until the next COMMIT or ROLLBACK command encountered. But a transaction will also ROLLBACK if the database is closed or if an error occurs. BEGIN; or BEGIN TRANSACTION; • The COMMIT Command: The COMMIT command is the transactional command used to save changes invoked by a transaction to the database. The COMMIT command saves all transactions to the database since the last COMMIT or ROLLBACK command. COMMIT; or END TRANSACTION; • The ROLLBACK Command: The ROLLBACK command is the transactional command used to undo transactions that have not already been saved to the database. The ROLLBACK command can only be used to undo transactions since the last COMMIT or ROLLBACK command was issued. ROLLBACK; For a detailed example, see notes below.
  • 15. www.inforepos.com SQLite UNION | UNION ALL • UNION operator is used to combine the result from multiple SELECT statements into a single result set. • The default characteristic of UNION is, to remove the duplicate rows from the result. The DISTINCT keyword which is optional does not make any effect, because, by default, it specifies duplicate-row removal. But if we use the optional keyword ALL, the duplicate-row removal does not happen and the result set includes all matching rows from all the SELECT statements. SELECT ... UNION [ALL | DISTINCT] SELECT ... [UNION [ALL | DISTINCT] SELECT ...] Select employee_id, job_id FROM employees UNION Select employee_id,job_id FROM job_history;
  • 16. www.inforepos.com SQLite UNION | UNION ALL • UNION ALL operator does not eliminate duplicate selected rows and returns all rows. UNION ALL operator returns all the rows from both the queries and no duplication elimination happens. Compare: UNION operator returns the combined result from multiple SELECT statements into a single result set but exclude the duplicate rows where as the UNION ALL operator avoids the elimination of duplicate selected rows and returns all rows. Select employee_id, job_id,department_id FROM employees UNION ALL Select employee_id,job_id,department_id FROM job_history;
  • 17. www.inforepos.com SQLite Collating Sequences At the time of comparison of two strings, in SQLite, it uses a collating sequence or collating function to understand which string is greater or whether the two strings are equal. SQLite has three built-in collating functions: • BINARY - Compares string data using memcmp(), regardless of text encoding. • NOCASE - It is almost same as binary, except the 26 upper case characters of ASCII are folded to their lower case equivalents before the comparison is performed. • RTRIM - The same as binary, except that trailing space characters, are ignored.
  • 18. www.inforepos.com SQLite Collating Sequences Text comparison cola=colb is performed using the BINARY collating sequence. SELECT coln FROM test WHERE cola = colb ORDER BY coln; Text comparison cola=colb is performed using the RTRIM collating sequence. SELECT coln FROM test WHERE cola = colb COLLATE rtrim ORDER BY coln; Text comparison cold=cola is performed using the NOCASE collating sequence. SELECT coln FROM test WHERE cold = cola ORDER BY coln; Text comparison cola=cold is performed using the BINARY collating sequence. SELECT coln FROM test WHERE cola = cold ORDER BY coln; Text comparison 'pqr'=colc is performed using the RTRIM collating sequence. SELECT coln FROM test WHERE 'pqr' = colc ORDER BY coln; Text comparison colc='pqr' is performed using the RTRIM collating sequence. SELECT coln FROM test WHERE colc = 'pqr' ORDER BY coln; Grouping is performed using the NOCASE collating sequence (Values 'pqr', 'PQR', and 'Pqr' are placed in the same group). SELECT count(*) FROM test GROUP BY cold ORDER BY 1; Grouping is performed using the BINARY collating sequence. 'pqr' and 'PQR' and 'Pqr' form different groups SELECT count(*) FROM test GROUP BY (cold || '') ORDER BY 1; Sorting or column colc is performed using the RTRIM collating sequence. SELECT coln FROM test ORDER BY colc, coln; Sorting of (colc||'') is performed using the BINARY collating sequence. SELECT coln FROM test ORDER BY (colc||''), coln; Sorting of column colc is performed using the NOCASE collating sequence. SELECT coln FROM test ORDER BY colc COLLATE NOCASE, coln;
  • 20. www.inforepos.com SQLite Aggregate Functions • avg(X) • count(*) • count(X) • group_concat(X) • group_concat(X,Y) • max(X) • min(X) • sum(X) • total(X) Note: GROUP_CONCAT(X) / GROUP_CONCAT(X, Y) The group_concat() function returns a string which is the concatenation of all non-NULL values of X. If parameter Y is present then it is used as the separator between instances of X. A comma (",") is used as the separator if Y is omitted. The order of the concatenated elements is arbitrary. SUM(X) / TOTAL(Y) The result of total() is always a floating point value. The result of sum() is an integer value if all non-NULL inputs are integers. If any input to sum() is neither an integer or a NULL then sum() returns a floating point value which might be an approximation to the true sum. COUNT(X) / COUNT(*) The count(X) function returns a count of the number of times that X is not NULL in a group. The count(*) function (with no arguments) returns the total number of rows in the group.
  • 21. www.inforepos.com SQLite DATE & TIME functions • SQLite supports five date and time functions All above five date and time functions take a time string as an argument. The time string is followed by zero or more modifiers. S.No. Function Example 1 date(timestring, modifiers...) This returns the date in this format: YYYY-MM-DD 2 time(timestring, modifiers...) This returns the time as HH:MM:SS 3 datetime(timestring, modifiers...) This returns YYYY-MM-DD HH:MM:SS 4 julianday(timestring, modifiers...) This returns the number of days since noon in Greenwich on November 24, 4714 B.C. 5 strftime(timestring, modifiers...) This returns the date formatted according to the format string specified as the first argument formatted as per formatters explained below.
  • 22. www.inforepos.com SQLite DATE & TIME functions • Time Strings: A time string can be in any of the below formats. • Modifiers: The time string can be followed by zero or more modifiers that will alter date and/or time returned by any of the above five functions. Modifiers are applied from left to right and below table shows the available modifiers in SQLite. • Formatters: SQLite provides very handy function strftime() to format any date and time. You can use below substitutions to format your date and time.
  • 24. THANK YOU For All Queries : info@inforepos.com
  • 25. Proven Database for IIOT Applications SQLite Learn the Music of Database