Monday, October 7, 2019

How to Create Database in SQLite? Explain 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.

No comments:

Post a Comment

Lab 09: Publish and subscribe to Event Grid events

  Microsoft Azure user interface Given the dynamic nature of Microsoft cloud tools, you might experience Azure UI changes that occur after t...