C program to create SQLite database dynamically in Linux

Here, we are going to write a C program to create SQLite database dynamically in Linux.
Submitted by Nidhi, on February 12, 2021


The following packages need to be installed in the ubuntu machine for Sqlite connectivity using the C program.

sudo apt install sqlite3
sudo apt install gcc
sudo apt install libsqlite3-dev

Problem Solution:

In this program, we will create a database using the sqlite3_open() function dynamically in Linux.

Program/Source Code:

The source code to create a SQLite database dynamically is given below. The given program is compiled and executed successfully on Ubuntu 20.04.

//C program to create database dynamically in linux.

#include <sqlite3.h>
#include <stdio.h>

int main(void)
    sqlite3* db_ptr;
    int ret = 0;

    ret = sqlite3_open("MyDb.db", &db_ptr);

    if (ret == SQLITE_OK) {
        printf("Database created successfully\n");


    return 0;


$ gcc create_db.c -o create_db -lsqlite3 -std=c99
$ ./create_db 
Database created successfully

In the above program, we included the sqlite3.h header file to uses SQLITE related functions. Here, we created "MyDb.db" database using sqlite_open() function. The sqlite_open() function is used to open an existing database and if the database is not present then it will create a specified database automatically.

C SQLite Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.