SQLite Create Database

  Total Views : 45
  Comments : 0
 
  Keywords : Sqlite create database if not exists using command line tool with example, Use create database command in sqlite command line tool with example, Create a new database in sqlite with example

Here we will learn how to create database in sqlite using command line tool with example and how to use database command in sqlite to create database with example.

SQLite Create Database

Like other Relational Database Systems, SQLite does not use CREATE DATABASE command to create the database. Instead it is very simple to create database in SQLite and the complete SQLite database is stored in a single cross-platform disk file. 

 

Following is the syntax to create database in SQLite.

 

sqlite> Sqlite3 database-name.db

Now we will see how to create database using SQLite command-line tool. For that open installed sqlite command line tool directly or open it from command prompt.

 

Open command prompt and navigate to the folder where your sqlite command-line tool installed. During installation we created SQLite folder in "C" directory and copied sqlite3.exe in it so now we are navigating to respective SQLite folder like as shown below.

 

open sqlite command line tool to run commands

 

Once we navigated to SQLite installed folder now type the following command to create database.

 

Sqlite3 db1.db

By above command SQLite create database named db1. If there is already a database called db1 then it will open for you.

 

sqlite create new database using sqlite command line tool

 

You can see the database that you have just created by redirecting to sqlite command-line location as follows.

 

SQLite Database Created DB File Location

 

You can see db1.db is created at c:/sqlite location. You can also ensure that db1 database is created or not by following command.

 

.databases

From this command, you can see the list of database created. You can also see db1 in this list. 

 

SQLite Available Database List

SQLite Create Database in Specific Location

By default, SQLite creates a new database in a location in which sqlite3.exe is reside. Now, if you create a new database in your preferred location then you can do this by following below steps.

 

Go to the folder where your sqlite3.exe is resided like as shown below.

 

Open sqlite3 exe file to create new database

 

Now double click on sqlite3.exe and run the following command.

 

.open C:/Users/Admin-PC/Desktop/student.db

This command will create a database named student on desktop folder. Here, it is important to note that .open command is used as two ways. If database already created on a specific location, then it will open the database otherwise it will create a new one.

 

Here whenever we run above SQLite command first it will check for student.db in location C:/Users/Admin-PC/Desktop/. If it finds, then it will open the database otherwise it will create new database named student.db.

 

SQLite New Database in Different Location

 

This is how we can create databases in SQLite based on our requirements.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User