EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials SQLite Tutorial SQLite Create Database
Secondary Sidebar
What is MapReduce in Hadoop?

Virtualization in Cloud Computing

Bias-Variance

MongoDB vs Postgres

Oracle Java

Data Analysis Tools

SQLite Create Database

SQLite Create Database

Definition of SQLite Create Database

SQLite provides the create database functionality to users, in which that user can be able to create a database as per their requirement. SQLite gives you the alternative of making another database (or opening a current one) each time you start the order line utility. At the point when you use sqlite3 to begin the command line utility, you can alternatively affix a data set document name. In the event that a database exists of that document name, it will be opened. Else it will be made. In another word, we can say to make another database in SQLite, basically, enter sqlite3 followed by the name of the document that you wish to use for the information base.

Syntax:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Sqlite3 specified database name.db

Explanation

Creating database syntax is very simple. We can easily create a database by using the above syntax. Here, Sqlite3 is a useful library to implement the SQL database engine. A specified database name means the actual name of the database that we need to create. Finally, here we use db, which is the extension of the database.

How to Create a Database in SQLite?

Now let’s see how we can create the database in SQLite as follows.

1. First, we need to open the command-line interface that is the cmd from the start and type their cmd and open it.

2. After that, cmd opens in the default folder of any machine.

3. In the next step, find the desired SQLite location, which means it is located on the user machine.

4. After that, select the specified file and navigate where the sqlite3.exe is placed by using the command-line tool.

5. Once we are inside the SQLite, we can perform the create database operation and many more operations as per the requirement.

The SQLite project gives a basic order line program named sqlite3 (or sqlite3.exe on Windows) that permits the client to physically enter and execute SQL proclamations against an SQLite data set or against a ZIP document. This record gives a concise acquaintance on how to utilize the sqlite3 program. Start the sqlite3 program by composing “sqlite3” at the order brief, alternatively followed by the name of the document that holds the SQLite information base (or ZIP file). In the event that the named document doesn’t exist, another information base record with the given name will be made consequently. In the event that no information base document is indicated on the order line, an impermanent data set is made, at that point erased when the “sqlite3” program exits. On startup, the sqlite3 program will show a concise pennant message at that point, brief you to enter SQL. Type in SQL explanations (ended by a semicolon), press “Enter”, and the SQL will be executed.

End the sqlite3 program by composing your framework End-Of-File character (normally a Control-D). Utilize interference with character (typically a Control-C) to stop a long-running SQL explanation.
Ensure you type a semicolon toward the finish of each SQL order! The sqlite3 program searches for a semicolon to know when your SQL order is finished. In the event that you preclude the semicolon, sqlite3 will give you a continuation brief and hang tight for you to enter more content to be added to the current SQL order. This component permits you to enter SQL orders that length numerous lines.

Examples of SQLite Create Database.

Now let’s see the different examples of creating databases as follows.

We already discussed some steps about how we can open SQLite on cmd now; let us see practically how we can create a database as follows.

First, as per mentioned above, step on cmd and navigate to the user’s respective SQLite folder; sometimes, the folder name may change depending on the user. When we navigate inside the SQLite, then it shows something like the below screenshot as follows.

cd SQLite

SQLite Create Database 1

After that, type the dir command to list the all available directory inside the SQLite folder. End result of the above command is shown in the below screenshot as follows.

dir

SQLite Create Database 2

See in above screenshot demo. db is an already created database; now, we need to create another database. At that time, we can use the following statement as follows.

sqlite3 sample.db

SQLite Create Database 3

Explanation

In the above example, we use sqlite3 to create the new database; here sample is the database name that we need to create, as shown in the above statement. End result of the above command is shown in the below screenshot as follows.

We can also use the dir command to list all created databases. End result of the above command is shown in the below screenshot as follows.

dir

dir command output

Now let’s see another way to create a database as follows.

Attach as Database method

Likewise, you can utilize the ATTACH DATABASE order to make a data set from inside the SQLite3 order utility.
At the point when you utilize this order, give a record name to the data set, just as an assumed name for the information base. In the event that the record as of now exists, it will connect that information base document.

Syntax:

ATTACH DATABASE ‘specified database name.db’ AS same database name as specified;

Explanation

In the above syntax, we use attach database command to create a database on SQLite; here, the specified database name means the actual database name that we need to create. One more important thing here is the database name we refer to, as it is mentioned after the AS keyword as shown in syntax.

Example

ATTACH DATABASE ‘test. db’ AS Test;

Explanation

In the above example, we use the attach database command to create a new database name as Test.

Now we need to see the created database; then, we can use the following command as follows.

.databases

Explanation

End result of the above command is shown in the below screenshot as follows.

output of the code

Conclusion

We hope from this article you have understood about the SQLite create database. From the above article, we have learned the basic syntax of creating a database, and we also see different examples of creating a database. From this article, we learned how and when we use SQLite to create a database.

Recommended Articles

This is a guide to SQLite Create Database. Here we discuss the Introduction, syntax, How to create a database in SQLite? and examples. You may also have a look at the following articles to learn more –

  1. SQL Injection Attack
  2. SQL COALESCE
  3. SQL pivot
  4. SQL Formatter
Popular Course in this category
SQLite Tutorial (3 Courses, 1 Project)
  3 Online Courses |  1 Hands-on Projects |  11+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more