-> SQLite is an open source, zero-configuration, self-contained, stand alone, transaction relational database engine designed to be embedded into an application.
-> SQLite does not have a separate server process. It reads and writes directly to ordinary disk files.
-> SQLite doesn’t require configuration. No setup or administration required.he
Create Database:
The sqlite3 command is used to create database. But, if the database does not exist then a new database file with the given name will be created automatically.
cmd:sqlite3 test.db
-> To see the databases:
cmd: .databases
-> To quit from the database
cmd: .quit
->dump Command:The .dump dot command is used to export complete database in a text file by using SQlite command at command prompt.
cmd: sqlite3 test.db .dump > test.sql
Attach database:
To select a particular database and after using this command, all SQLite statements will be executed under the attached database.
cmd:ATTACH DATABASE ‘DatabaseName’ As ‘Alias-Name’;
Note: It will also create a database if the database is not already present, otherwise it will only attach a database file name with the logical database Alias-Name.
Detach Database:
It is used to detach the alias-named database from a database connection which was previously attached by using ATTACH statement.
cmd: DETACH DATABASE ‘Alias-Name’
To see the list tables:
cmd: .tables
SQLite Import:
-> Import a CSV file into SQLite table by using sqlite3 tool and .import command. This command accepts a file name, and a table name.
-> Here, file name is the file from where the data is fetched and the table name is the table where the data will be imported into. In the absence of the table, it will create the table automatically according to the data in CSV file.
cmd: .mode csv
cmd:.import /Users/javatpoint1/Desktop/sqlite/student.csv EMPLOYEE
To see the records:
cmd: .mode column
cmd: SELECT * FROM EMPLOYEE;
Note: .mode column is used before SELECT statement to show the data in tabular form and specifies the columns.
SQLite Export:
-> To export data from SQLite database to CSV file. We can export the whole table or less according to your query.
-> .once command is used to export data to a CSV file followed by the file path/name where we want to write the file.
cmd: .header on
cmd: .mode csv
cmd: .once /Users/javatpoint1/Desktop/sqlite/student.csv
cmd: SELECT * FROM STUDENT;
Code explanation:
.header on: It specifies that headers are enabled. This is optional. If you disable headers, the CSV file simply won’t contain any data.
.mode csv: It specifies that CSV mode is enabled.
.once: It specifies that the output to be written to the CSV file and next is the exact location.
After execution of the above code, a CSV file is created on the specified location.
-> To open the csv file automatically
cmd: .system /Users/javatpoint1/Desktop/sqlite/student.csv
–