Simple Way To Create Sqlite Database

Introduction

One of the biggest dilemmas before starting the implementation of a new project is the choice of the technology of the database.

In some projects, we need just to store data in an embedded DB in the application with a minimal set of security without needing to install a DBMS withseveral DB services or processes that can complexify the environment without any need. In these cases, Sqlite can be the best choice.

Prerequisite

  • SqliteStudio: Sqlite Studio is a tool that allows to perform several operations on a Sqlite database (creation, update, export ...) and it gives the possibility to do it using scripting or the user interface. It can be downloaded from the following link https://sqlitestudio.pl/

Step 1. Download SqliteStudio

Once you download the sqliteStudio, you will get a binary folder that contains all the needed DLLs and the exe.

Store it in a directory of your choice.

Step 2. Create the database

To create a database you need toopen the command line and then navigate to your SqliteStudio's folder.

Simple Way To Create Sqlite Database

Once you are in the folder of binaries, you can use thesqlitestudiocli.exe to create your database. let's suppose that we are building a products database.

So type the command as follows, and your DB will be created in the same folder.

Type Ctrl+C to leave.

captureDB

Step 3. Add your database using Sqlite studio

Now go to your downloaded folder and open the SQLiteStudio.exe and then click the icon to add the database

add DB

Then browse your folders to add yoursDB.In our case products.db

DB Location

Step 4. Create your tables

Once you added the DB you should have it in your databases list, Select it and click the icon to add a table

table create

Step 5. Create the table structure

You are in the tab Structure of the table, you can add your needed columns with their types. You can also add a constraint if needed.

For example for the following screenshot, we are creating the barcode column having the type varchar and it's a primary key

consatratint

Step 6. Commit your changes

Once you have created all your needed columns, you can commit your changes and then they will be effective

commit

Once the script will be shown on the screen, confirm it.

If no error occurs you will have the following message in the status area.

status

You can switch to the tab data to refresh, add, or delete your database's data

operations

Conclusion

This article showed how to create a basic database with only one table.

The most important challenge is to have a good model that simplifies the design on the applicative side and also simplifies the mapping to your application's object using an ORM.


Similar Articles