.sql

What is a .sql file?

SQL Script · Code and data · IBM (SQL language) · 1970s

A SQL file is a plain-text script of database commands, such as creating tables or inserting and querying data. Opening it is harmless, but running it against a database executes those commands, which can change or delete data.

Category
Code and data
Type
Plain text
Is a .sql file safe to open? Safe to open, it is plain text. The caution is running it: executing a .sql runs its commands against a database and can drop tables or delete data. Read it first and only run trusted scripts against a database you can restore.

What is a .sql file used for?

A .sql file holds SQL statements: the language databases speak, with commands like SELECT, INSERT, CREATE and DROP. It is often a database dump (a backup as text), a schema setup, or a migration.

Reading a .sql is completely safe, it is just text. The care is in running it: executing the script against a database carries out every command in it, which can include deleting rows or dropping whole tables.

You run one in a database client such as psql, the MySQL command line, SQLite, or a GUI like DBeaver, pointed at the database you want to change.

Open it in a text editor first to see exactly what it will do, especially any DROP or DELETE statements.

What opens a .sql file?

The .sql format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.

Windows

  • VS Code or Notepad++ (to read/edit)
  • DBeaver / a DB client (to run)

macOS

  • VS Code (to read/edit)
  • DBeaver / a DB client (to run)

Linux

  • Any text editor (to read/edit)
  • psql / mysql / sqlite (to run)

Web

  • Online SQL editors (against a test database)

Open a .sql file step by step

  1. Confirm the file really is a .sql. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with VS Code or Notepad++ (to read/edit) or DBeaver / a DB client (to run).
  3. On Mac, use VS Code (to read/edit) or DBeaver / a DB client (to run).
  4. On Linux, try Any text editor (to read/edit) or psql / mysql / sqlite (to run).
  5. Still stuck? Convert the .sql to Not convertible, which opens more widely.

Why can't I open my .sql file?

Almost always because no installed app understands SQL. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .sql at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

How to convert a .sql file

You can convert a .sql file to Not convertible using a conversion tool or the export menu of an app that opens it.

SQL has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

Frequently asked questions

What is a .sql file?

A SQL file is a plain-text script of database commands, such as creating tables or inserting and querying data. Opening it is harmless, but running it against a database executes those commands, which can change or delete data.

How do I open a SQL file?

Open it in any text editor to read the commands. To actually run it, load it into a database client such as DBeaver, psql or the MySQL command line and execute it against your database.

How do I run a .sql file?

In a database client, connect to your database and run the script, for example psql -f file.sql, mysql < file.sql, or the Run button in a GUI. Read it first, since it will carry out every command it contains.

Related formats

Sources

Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.