From SQLite to SQL Script


Do you have a table of data in SQLite and you want to generate a SQL script that can build the table and its data again. Perhaps you want to import it into another relational database such as SQL Server. If you have the database open in DB Browser, it is easy to generate the SQL script.

I will start with a very simple example. We will have a single database file that contains tables. In the main menu at the top of DB Browser, click on File > Export > Database to SQL file… You will se a dialog box similar to the one pictured below.

From SQLite to SQL Script - Click to Enlarge

The screenshot above shows the dialog box and a bit of the background of DB Browser at the left and on the top. You can see the data in the table we are using to create the SQL file. Here is what the wizard produced in the file. I opened it with otepad++.

BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "tbl_new_names" (
	"Name"	TEXT,
	"Number"	INTEGER
);
INSERT INTO "tbl_new_names" ("Name","Number") VALUES ('Bobby',79),
 ('Janice',22),
 ('Kat',43);
COMMIT;

I could test this by importing the table back in as a different table, perhaps called tbl_new_names_2. I would need to change it in two locations in the script. How do we do that? Check out the post called SQL Script into SQLite.

Leave a comment

Your email address will not be published. Required fields are marked *