119

I have a few SQLite database files. I want to know the database file version (if the database was created with sqlite2 or sqlite3 or any other main/sub version) not the SQLite library or driver or user_version or schema_version.

0

11 Answers 11

178

You can write this command in any sqlite explorer which will give the sqlite version

select sqlite_version();
3
  • 75
    This will return the library version, not the database file version.
    – laalto
    Jan 15, 2014 at 15:26
  • 2
    @laalto comment confirmed by this official doc: sqlite.org/lang_corefunc.html#sqlite_version Sep 10, 2019 at 12:26
  • Indeed, the preceding function in @Paolo link refer to sqlite_source_id(), with that you just has to see SQLite release date and you can get the version Oct 21, 2019 at 7:25
108

You can get version number of a database file by the Magic Header String:

  • sqlite2 ==> first 48 bytes
  • sqlite3 ==> first 16 bytes

$ head -c 48 file2.db
** This file contains an SQLite 2.1 database **

$ head -c 16 file3.db
SQLite format 3

The easier way is using the file command:

$ file file2.db
file2.db: SQLite 2.x database

$ file file3.db
file3.db: SQLite 3.x database
2
  • 1
    The naive way is to open the file with Notepad++ (don't do this if the file is big!) Sep 10, 2019 at 12:30
  • @PaoloFulgoni XVI32 is also a nice tool for these tasks. Jul 25, 2020 at 17:59
39

Get user_version

Run SQL: PRAGMA user_version;

Get schema_version:

Run SQL: PRAGMA schema_version;

When create database file (.db), user_version can be set by user.

1
  • pragma schema_version is what was asked for.
    – Wolf
    Dec 5, 2023 at 13:21
24

The correct answer from version 3 of sqlite program is:

sqlite3 --version
1
  • 9
    This is the version of the sqlite3 program, not the version of the database created by SQLite.
    – user264541
    Mar 25, 2019 at 19:49
5

You can extract the information from the file header. It will require you to open the database file 'by hand' but I don't know if there is an API function to get this information.

2

You have to open the python shell then write these steps:

import sqlite3

sqlite3.sqlite_version
2
  • 3
    This gives you the sqlite3 version used by Python. Apr 29, 2019 at 10:48
  • May not be correct for some users, but I should point out that in my case, using Django on Ubuntu 18.04, it actually was the only way that worked. Trying "sqlite3 --version" at the command shell, oddly, would claim that sqlite3 was not installed, whereas doing it inside python told me what version django/python was using, which is what I was looking for.
    – rossdavidh
    Jun 13, 2019 at 19:17
2
import sqlite3

conn = sqlite3.connect('example.db')

cursor = conn.cursor()

cursor.execute('SELECT SQLITE_VERSION()')

data = cursor.fetchone()
print(f"SQLite version: {data[0]}")
1
  • Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation? Aug 14, 2023 at 0:58
1

Check manual file

sqlite3.version The version number of this module, as a string. This is not the version of the SQLite library.

sqlite3.version_info The version number of this module, as a tuple of integers. This is not the version of the SQLite library.

sqlite3.sqlite_version The version number of the run-time SQLite library, as a string.

sqlite3.sqlite_version_info The version number of the run-time SQLite library, as a tuple of integers.

0

I found this to be the easiest method to determine the version of sqlite. Run the Python IDLE Shell, then do the following:

>>> import sqlite3
>>> sqlite3.version
'2.6.0'

In my case it was 2.6.0. Hope this helps... Mark

2
  • 2
    fyi, to run the Python IDLE Shell, simply type in python in the terminal, you'll then see >>>
    – thehme
    Dec 5, 2015 at 4:54
  • 15
    This gives the version of the module, not the SQLite version. To do so, use sqlite3.sqlite_version. docs.python.org/3.5/library/… Jun 21, 2016 at 11:40
0

In command prompt, if you type sqlite3 and hit enter, it will automatically give the version number at the very first.

sqlite3

enter image description here

1
  • Read careful: even if answered a lot, this was not asked for.
    – Wolf
    Dec 5, 2023 at 13:15
-1

If you have a data connection to it in Visual Studio, you can right click on the data base in Server Explorer, select properties, and the version will be shown in the properties window, (under Version, surprisingly). You might need to left click the database first to open it.

1
  • 3
    I think OP is asking about sqlite not sql-server. Apr 22, 2013 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.