SQLite Tutorial SQLite Advanced SQLite Database SQLite References

SQLite - CREATE DATABASE



The SQLite, sqlite3 command is used to create a new SQLite database.

Syntax

The syntax of using sqlite3 statement is given below:

$sqlite3 DatabaseName.db

Please note that to create any database, appropriate privilege is required. Along with this, the database name should be unique within the RDBMS.

After creating the database successfully, sqlite3 command will provide a sqlite> prompt. Once a database is created, the .database dot command can be used to see the list of available databases.

sqlite> .database

Example: create a database

To create a database with name testDB, the following statement can be used:

$sqlite3 testDB.db

The .database Command

After creating the database, the SQLite .database dot command can be used to see the list of databases available in the RDBMS.

sqlite> .database
seq  name             file
---  ---------------  ----------------------
0    main             /home/sqlite/testDB.db

The .quit Command

To quit the sqlite prompt, the SQLite .quit dot command can be used.

sqlite> .quit

The .dump Command

The .dump dot command is used to export complete database in a text file by using SQlite command at command prompt.

$sqlite3 testDB.db .dump > testDB.sql

The above command will convert the entire contents of testDB.db database into SQLite statements and dump it into ASCII text file testDB.sql. To perform the restoration from the generated testDB.sql, the following command can be used:

$sqlite3 testDB.db < testDB.sql