SQLite - SPLessons

SQLite Database

Chapter 6

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQLite Database

SQLite Database

shape Description

SQLite Database is a working framework information center that executes an independent, zero-arrangement, value-based SQL database appliance and serverless. SQLite is the uttermost extensive setup for SQL database appliance in the universe. The SQLite source code is in terms of free domain. SQLite is one of the quickest developing database apparatuses as far as development and fame.

SQLite is one of the database technology that is zero-configured, which implies it doesn’t need to configure in individual PC’s that resembles with other database technologies. SQLite mechanism is not a standalone strategy like different databases, every one can link it progressively or statically according to ones prerequisite with each operation. The SQLite admittance its storage documents straightforwardly.

Create database

shape Description

By using SQLite3 Command in SQLite one can create new database in SQLite without any specific privileges for creating or accessing the database.

shape Syntax

$SQLite3 DatabaseName.db

SQLite3 => Is a database.

Database Name => Name of the database.

shape Examples

The below example describes the creation of  new database.

SQLite version 3.13.0 2016-05-18 10:57:30
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>

The above example describe the creation of new database in SQLite. TestDB.db is a file that is made by utilizing the above command. The SQLite engine utilize these files in the SQLite database. At the time of creation of new database, SQLite>prompt is utilized by SQLite3 command and can be checked whether the new database is created or not by using the below command.

sqlite> .databases
seq  name             file

---  ---------------  ----------------------------------------------------------

0    main             /home/sqlite/testDB.db

sqlite>

Attach database

shape Description

ATTACH DATABASE articulation in SQLite utilizes to append different database and every single SQLite announcement will be assassinated under the connected database.

shape Syntax

ATTACH DATABASE ‘DatabaseName’As ‘Alias-Name’;

In the above ATTACH DATABASE statement, database name is attached with alias name using the basic syntax of logical operation.

shape Examples

In the below example,the ATTACH DATABASE statement will perform some logical operations.

sqlite> ATTACH DATABASE 'testDB.db' as 'edition';
sqlite> .database
seq  name             file

---  ---------------  ----------------------------------------------------------

0    main             /home/sqlite/testDB.db
2    edition          /home/sqlite/testDB.db

Detach database

shape Description

In the SQLite Database association, Attach Database explanation is used to attach an alias name to a current database, and in the way DETACH DATABASE articulation is used for detaching and separating the database that is named inside the database. In the event that diverse names will be appended to single database, then SQLite DETACH command will scratch off the name and connect whatever remains of the database. While temp or main cannot be detached from the database.

shape Syntax

DETACH DATABASE ‘Alias-Name’;

Alias-Name => Is the alias name

shape Examples

Below example shows how to detach the database.

sqlite> ATTACH DATABASE 'Edition' as 'presentDB';
sqlite> .database
seq  name             file

---  ---------------  ------------------------------

0    main              /home/sqlite/testDB.db

2    edition           /home/sqlite/testDB.db

3    presentDB        /home/sqlite/testDB.db
sqlite> DETACH DATABASE 'presentDB';
sqlite> .databases
seq  name             file

---  ---------------  ----------------------------------------

0    main              /home/sqlite/testDB.db

2    edition          /home/sqlite/testDB.db

In the above example, the presentDB is detached from the SQLite database and no more presentDB database exists in the SQLite Database.

Summary

shape Key Points

  • SQLite Database – Is a working framework information center.
  • Create Database – Create command is used to create new database.
  • Attach Database – Is used to append multiple database.
  • Detach Database – Is used to remove the current database.