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.
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.
You can see the database that you have just created by redirecting to sqlite command-line location as follows.
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 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.
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.
This is how we can create databases in SQLite based on our requirements.
No comments:
Post a Comment