SQLite

How to Exit a Database in SQLite?

SQLite is a popular open-source relational database management system, which is a library of software that offers a compact, serverless SQL database engine. SQLite is known for its conciseness, speed, and simplicity, making it popular for embedded systems, mobile devices, and small-scale applications. SQLite’s databases are easy to create and use and compatible with various programming languages and operating systems.

In this article, we will discuss how to exit an SQLite 3 database.

How to Exit an SQLite Database?

Before understanding how to exit an SQLite database, it is important for you to be in the working mode of SQLite database. This means that you should have successfully connected to the SQLite database and be able to execute commands and queries against it. Without being in working mode, you won’t be able to perform any operations or exit the database.

Here in the below-given steps, we are creating a Table in SQLite and then using the appropriate ways to exit the database.

Step 1: Create an employees table in the SQLite Database using.

CREATE TABLE employees (
    id INTEGER PRIMARY KEY,
    name TEXT,
    department TEXT,
    salary INTEGER
);

 

Step 2: Next, insert some values in the employees table

INSERT INTO employees (name, department, salary) VALUES ('Penny', 'Sales', 50000);
INSERT INTO employees (name, department, salary) VALUES ('Jake', 'Marketing', 65000);
INSERT INTO employees (name, department, salary) VALUES ('Mike', 'Sales', 55000);
INSERT INTO employees (name, department, salary) VALUES ('Emily', 'HR', 45000);
INSERT INTO employees (name, department, salary) VALUES ('David', 'Marketing', 76000);

 

Now, to exit a database in SQLite, you can use:

1: .exit Command

The .exit command is a widely used command in SQLite that allows you to exit the database. The .exit command will close all open database connections and terminate any running transactions. This command is useful when working with the command-line interface of SQLite because it exits the sqlite3 program.

.exit

 

2: .quit Command

You can also use the .quit command in the sqlite3 command line tool to exit the database. This command gracefully terminates the current session and closes the connection, releasing any acquired resources.

.quit

 

Conclusion

Exiting an SQLite database involves disconnecting from the database connection and terminating any running transactions. This can be achieved by running the .exit command or the .quit command. This article has presented both these methods in an easy manner, allowing users to have a quick understanding of them.

About the author

Hiba Shafqat

I am a Computer Science student and a committed technical writer by choice. It is a great pleasure to share my knowledge with the world in which I have academic expertise.