Sqlite3 How To Create Database
Here we will learn how to create a database in SQLite using a command-line tool with example and how to use database command in sqlite to create the 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 a database in SQLite, and the complete SQLite database is stored in a single cross-platform disk file.
Following is the syntax to create a database in SQLite.
sqlite> Sqlite3 database-name.db
Now we will see how to create a database using the SQLite command-line tool. For that open installed sqlite command-line tool directly or open it from the command prompt.
Open command prompt and navigate to the folder where your sqlite command-line tool installed. During installation, we created theSQLite 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 a database.
Sqlite3 db1.db
By the above command, SQLite creates a 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 thedb1 database is created or not by the following command.
.databases
From this command, you can see the list of databases created. You can also see db1 on this list.
SQLite Create Database in Specific Location
By default, SQLite creates a new database in a location in which sqlite3.exe is residing. Now, if you create a new database in your preferred location then you can do this by following the 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 the 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 a new database named student.db.
This is how we can create databases in SQLite based on our requirements.
Sqlite3 How To Create Database
Source: https://www.tutlane.com/tutorial/sqlite/sqlite-create-database
Posted by: williamsalannow.blogspot.com
0 Response to "Sqlite3 How To Create Database"
Post a Comment