How to open .SQL files on Windows

To open .SQL files on Windows, to view/edit: Right-click the .sql file → Open with → choose a text editor (for example, Notepad).

Step-by-step instructions

  1. To view/edit: Right-click the .sql file → Open with → choose a text editor (for example, Notepad).
  2. To execute in PostgreSQL: open Command Prompt and run psql, then use psql to run the script file (see PostgreSQL psql documentation for the exact command and options).
  3. To execute in MySQL: use the MySQL command-line client or MySQL Workbench and run/import the .sql script as shown in the MySQL tutorial source.

Common issues

Double-clicking opens the file in the wrong program

.sql is plain text, so the OS may associate it with an unexpected editor or a database tool you don’t want to use for viewing.

  1. Use “Open with” to choose your preferred text editor for reading/editing.
  2. If you need to run it, open your database client (for example psql) and execute the script from there instead of double-clicking.

Script runs but fails with syntax errors

SQL syntax and supported features can vary between database systems, so a script generated for one product may not run unchanged on another.

  1. Confirm which database the script targets (for example PostgreSQL vs MySQL) and run it using the matching client/tool (psql for PostgreSQL; MySQL CLI/Workbench for MySQL).
  2. If you must run it on a different database, edit the SQL to match that database’s dialect and features, then try again.

Import/execute fails due to missing database connection or permissions

Executing a .sql file requires connecting to the right server/database and having privileges to create/alter objects or modify data.

  1. Verify you are connecting to the intended database instance and database name in your client (for example in psql connection options).
  2. Ask for or grant the required permissions before re-running the script.

Security note

.sql files can contain destructive statements (for example dropping tables or deleting data). Read the script in a text editor before executing it, especially if it came from an untrusted source.

Back to .SQL extension page