---
title: "Creating, Inserting, Updating and Deleting in SQLite"  
description: "In this blog, I’m explaining how to create and use the sqlite database in our application.  IntroductionSQLite is a relational database management sy"  
author: "Sumit Kesarwani"  
published: 2013-11-14  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/611/creating-inserting-updating-and-deleting-in-sqlite  
category: "database"  
tags: ["database"]  
reading_time: 3 minutes  

---

# Creating, Inserting, Updating and Deleting in SQLite

In this blog, I’m explaining how to create and use the [sqlite database](https://www.mindstick.com/articles/1554/crud-operation-in-asp-dot-net-using-sqlite-database) in our application.\

##### Introduction

SQLite is a relational [database management](https://www.mindstick.com/forum/34816/what-is-mapping-constraints-in-database-management-system) system which compliant [ACID properties](https://www.mindstick.com/articles/338513/acid-properties-in-database-transactions) and implements most of the SQL standard using a dynamically and weakly typed SQL syntax. SQLite is a popular choice as [embedded database](https://www.mindstick.com/forum/158399/what-is-the-difference-between-sqlite-and-other-embedded-database-systems) for local/client storage in [application software](https://answers.mindstick.com/qa/30813/what-is-application-software) such as web browsers. It is arguably the most widely deployed database engine, as it is used today by several widespread browsers, [operating systems](https://www.mindstick.com/articles/332551/operating-systems-trends-and-innovations-in-2023), embedded systems etc.

##### Installation

For installation of sqlite database in [your application](https://www.mindstick.com/forum/34702/please-tell-me-what-is-cross-site-scripting-and-how-is-it-harmful-for-your-application):-

Go to solution explorer, right click on it, select ‘Manage Nuget Package’ – a window will open and SQLITE on search textbox and select ‘System.Data.SQLte’ – it will install the sqlite database in your [application as](https://answers.mindstick.com/qa/41069/how-did-missouri-s-application-as-a-slave-state-in-1819-challenge-u-s-law) shown in the figure.

![Creating, Inserting, Updating and Deleting in SQLite](https://www.mindstick.com/blogs/032a90b9-b28e-46db-99d1-c0a1e661f092/images/f109d51b-1270-4bf2-b105-8d8ea7db0afc.jpg)

##### Creation of Database File

Once the SQLite database is installed in your application, now you can create the database file using the following statement:-

```
SQLiteConnection.CreateFile(@"D:\Sumit\Posting work\Blog\mySQLiteDatabase"); //Create a SQLITE database file
```

This statement will create a sqlite database file named nySQliteDatabse.

##### Create a table in database

```
SQLiteConnection dbConnection = new SQLiteConnection("Data Source="+path+";Version=3;"); //Create the connection with databasestring myQuery = "create table student (Id int, Name varchar(50), Address varchar(50))"; //SQL query to create a table with three columnsSQLiteCommand command = new SQLiteCommand(myQuery, dbConnection);//Create a SQLite command which accepts the query and database connectiondbConnection.Open();//Open the connection with databasecommand.ExecuteNonQuery();//Executes the SQL querydbConnection.Close();//Close the connection with database
```

The few above statements will create a table in the database named ‘student’ with three columns.

##### Insert

```
string myQuery = "insert into student (Id, Name, Address) values(001,'James Rowling', 'Manhattan')"; //SQL query to insert dataSQLiteCommand command = new SQLiteCommand(myQuery, dbConnection);//Create a SQLite command which accepts the query and database connection.dbConnection.Open();//Open the connection with databasecommand.ExecuteNonQuery();//Executes the SQL querydbConnection.Close();//Close the connection with database
```

##### Retrieving the data

```
string myQuery = "select * from student"; //SQL query to retrieve data from tableSQLiteCommand command = new SQLiteCommand(myQuery, dbConnection);//Create a SQLite command which accepts the query and database connection.dbConnection.Open();//Open the connection with databaseSQLiteDataReader dataReader = command.ExecuteReader();//Executes the SQL querydbConnection.Close();//Close the connection with database
```

##### Update

```
string myQuery = "update student set Name = 'Rose Salvatore' where Id = 002"; //SQL query to update data from table         SQLiteCommand command = new SQLiteCommand(myQuery, dbConnection);//Create a SQLite command which accepts the query and database connection.dbConnection.Open();//Open the connection with databasecommand.ExecuteReader();//Executes the SQL querydbConnection.Close();//Close the connection with database
```

##### Delete

```
string myQuery = "delete from student where Id = 002"; //SQL query to delete data from tableSQLiteCommand command = new SQLiteCommand(myQuery, dbConnection);//Create a SQLite command which accepts the query and database connection.dbConnection.Open();//Open the connection with databasecommand.ExecuteReader();//Executes the SQL querydbConnection.Close();//Close the connection with database
```

---

Original Source: https://www.mindstick.com/blog/611/creating-inserting-updating-and-deleting-in-sqlite

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
