.SQL SQL Script
.sql

SQL Script

SQL files store database commands as plain UTF-8 text — CREATE, SELECT, INSERT, UPDATE, DELETE, and schema definitions. Standardized as ISO/IEC 9075 since 1986, SQL is the dominant language for relational database management across MySQL, PostgreSQL, SQLite, SQL Server, and Oracle.

بنية الصيغة
Header schema
Records structured data
Query Languageapplication/sqlISO/IEC 9075Plain TextDDL / DML / DCL1986
بواسطة FileDex
غير قابل للتحويل

SQL scripts are database commands, not a convertible data format.

أسئلة شائعة

What is the difference between SQL and SQLite?

SQL is a query language defined by ISO/IEC 9075, used across all relational databases. SQLite is a specific database engine that stores data in a single file and uses a subset of SQL. MySQL, PostgreSQL, and Oracle are client-server databases requiring a running process; SQLite is embedded and serverless.

How do I prevent SQL injection attacks?

Always use parameterized queries (prepared statements) instead of string concatenation. In Node.js: db.query('SELECT * FROM users WHERE id = $1', [userId]). In Python: cursor.execute('SELECT * FROM users WHERE id = %s', (user_id,)). ORMs handle parameterization automatically.

Why does my SQL dump fail to import on a different database engine?

SQL dumps contain dialect-specific syntax: MySQL uses backtick quoting and AUTO_INCREMENT, PostgreSQL uses double quotes and SERIAL/IDENTITY, SQLite lacks ALTER TABLE support. Use a conversion tool like pgloader or manually adjust the syntax for the target engine.

How do I find slow queries in my database?

Use EXPLAIN (PostgreSQL/MySQL) or EXPLAIN QUERY PLAN (SQLite) before your SELECT statement to see the execution plan. Look for sequential scans on large tables — they indicate missing indexes. In production, enable the slow query log (MySQL) or pg_stat_statements extension (PostgreSQL).

ما يميز .SQL

What is a SQL file?

SQL (Structured Query Language) files contain database commands and queries written in the SQL language. They can include table creation statements (CREATE TABLE), data insertion (INSERT), queries (SELECT), stored procedures, triggers, and database migration scripts. SQL was developed at IBM in the 1970s based on Edgar Codd's relational model and standardized by ANSI in 1986. It remains the dominant language for relational database management nearly 50 years later.

اكتشف التفاصيل التقنية

SQL files are plain text and can be opened in any text editor. They are executed against a database server — the file itself contains no data, only the instructions for creating or manipulating it.

How to open SQL files

  • MySQL Workbench (Windows, macOS, Linux) — Free GUI for MySQL and MariaDB
  • DBeaver (Windows, macOS, Linux) — Free, connects to any database engine
  • pgAdmin (Windows, macOS, Linux) — PostgreSQL administration tool
  • VS Code (with SQLTools extension) — Syntax highlighting and query execution
  • Any text editor — View and edit the raw SQL text

Technical specifications

Property Value
Language Structured Query Language
Standard ISO/IEC 9075 (SQL:2023 is the latest)
Dialects MySQL, PostgreSQL, SQLite, T-SQL (SQL Server), PL/SQL (Oracle)
Encoding UTF-8
Comments -- single-line, /* */ multi-line
MIME type application/sql

Common use cases

  • Database migrations: Schema changes tracked as versioned SQL files (e.g., Flyway, Liquibase)
  • Data dumps: mysqldump and pg_dump export databases as .sql files for backup and transfer
  • Seed data: Initial data population for development and testing environments
  • Reporting queries: Complex multi-table joins and aggregations for business intelligence
  • ETL pipelines: Extract, transform, and load operations in data warehouses

SQL statement categories

-- DDL: Define structure
CREATE TABLE users (
  id   SERIAL PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email TEXT UNIQUE
);

-- DML: Manipulate data
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
SELECT name, email FROM users WHERE id > 10 ORDER BY name;
UPDATE users SET name = 'Bob' WHERE id = 1;
DELETE FROM users WHERE email IS NULL;

-- DCL: Control access
GRANT SELECT ON users TO readonly_role;

SQL is divided into DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control Language — COMMIT, ROLLBACK).

SQL dialects and portability

While the ISO standard defines core SQL, each database engine extends it with proprietary syntax. Code written for PostgreSQL may not run on MySQL without changes. Key differences appear in: string functions, date handling, window functions, JSON support, and auto-increment syntax (SERIAL vs AUTO_INCREMENT vs IDENTITY). SQLite is the most portable but lacks features like FULL OUTER JOIN.

Security: SQL injection

SQL injection is the most common and dangerous web vulnerability. It occurs when user input is concatenated directly into SQL queries:

-- DANGEROUS — never do this
"SELECT * FROM users WHERE name = '" + userInput + "'"

If userInput is ' OR '1'='1, the query returns all users. Always use parameterized queries or prepared statements, which separate SQL code from data and prevent injection entirely. Most ORMs (Sequelize, SQLAlchemy, ActiveRecord, Prisma) handle this automatically.

Performance considerations

Slow queries are the most common cause of database bottlenecks. Add indexes on columns used in WHERE, JOIN, and ORDER BY clauses. Use EXPLAIN (PostgreSQL/MySQL) or EXPLAIN QUERY PLAN (SQLite) to see how the database executes a query and whether it uses indexes. Avoid SELECT * in production code — select only the columns you need.

المرجع التقني

نوع MIME
application/sql
المطوّر
IBM (Edgar Codd / Donald Chamberlin)
سنة التقديم
1974
معيار مفتوح
نعم — عرض المواصفات

البنية الثنائية

SQL files are plain text with no binary structure. A SQL file contains one or more SQL statements, typically terminated by semicolons. Statements fall into four categories: DDL (Data Definition Language — CREATE, ALTER, DROP, TRUNCATE), DML (Data Manipulation Language — SELECT, INSERT, UPDATE, DELETE), DCL (Data Control Language — GRANT, REVOKE), and TCL (Transaction Control Language — BEGIN, COMMIT, ROLLBACK, SAVEPOINT). Comments use double-dash (-- comment) for single-line and /* comment */ for multi-line. Database dump files from mysqldump or pg_dump typically begin with a comment block containing the tool version, database name, and generation timestamp, followed by SET statements configuring the session (character set, foreign key checks), then CREATE TABLE statements, and finally INSERT statements with the data. Encoding is typically UTF-8, though some tools emit files with a UTF-8 BOM or use the database's configured character set. SQL files have no magic bytes, no header structure, and no maximum size limit — dump files from production databases regularly exceed multiple gigabytes.

1970Edgar Codd publishes 'A Relational Model of Data for Large Shared Data Banks' at IBM, defining the theoretical foundation1974IBM researchers develop SEQUEL (Structured English Query Language) as the first implementation of Codd's relational model1979Oracle releases the first commercial SQL database; Relational Software Inc. (later Oracle Corporation) ships V21986ANSI publishes SQL-86, the first formal SQL standard (ISO/IEC 9075)1992SQL-92 published — adds JOINs, CASE expressions, CAST, and standardizes string functions1999SQL:1999 adds regular expressions, recursive queries (WITH RECURSIVE), triggers, and procedural extensions2003SQL:2003 introduces window functions (OVER, PARTITION BY), XML support, and AUTO_INCREMENT-like sequences2016SQL:2016 adds JSON support (JSON_VALUE, JSON_TABLE), row pattern matching, and polymorphic table functions2023SQL:2023 published — adds GRAPH pattern matching, JSON type enhancements, and property graph queries
Execute a SQL file against SQLite أخرى
sqlite3 database.db < schema.sql

Redirects the SQL file as input to the sqlite3 CLI, executing all statements against the specified database. Creates the database file if it does not exist.

Export query results to CSV from SQLite أخرى
sqlite3 -header -csv database.db 'SELECT * FROM users WHERE active = 1;' > active_users.csv

The -header flag includes column names as the first CSV row. The -csv flag sets the output mode to comma-separated values. Results are redirected to a file.

Execute a SQL file against PostgreSQL أخرى
psql -U postgres -d mydb -f migration.sql

psql connects to the PostgreSQL database 'mydb' as user 'postgres' and executes all statements in the migration file. Use -v ON_ERROR_STOP=1 to halt on first error.

Dump a MySQL database to a SQL file أخرى
mysqldump -u root -p --single-transaction --routines mydb > backup.sql

Creates a consistent snapshot using --single-transaction (InnoDB). The --routines flag includes stored procedures and functions. The output is a complete SQL script that can recreate the database.

Check SQL syntax without execution using PostgreSQL أخرى
psql -d mydb -c 'EXPLAIN SELECT * FROM users WHERE id = 1;'

EXPLAIN parses and plans the query without executing it, revealing syntax errors and the query execution plan. Useful for validating SQL syntax and checking index usage.

SQL CSV export lossy Business analysts and data scientists need query results in spreadsheet-compatible format. Exporting SQL query output to CSV enables import into Excel, Google Sheets, and pandas DataFrames without database access.
SQL JSON export lossy Web applications and APIs consume JSON natively. Exporting SQL query results as JSON arrays of objects enables direct consumption by JavaScript frontends and NoSQL migration workflows.
SQL SQLITE render lossy Converting a MySQL or PostgreSQL dump to a portable SQLite database creates a single-file, zero-config database that can be shared, version-controlled, or embedded in desktop and mobile applications.
عالي

نقاط الضعف

  • SQL injection — user input concatenated into SQL queries allows attackers to bypass authentication, extract data, modify records, or execute administrative operations (DROP TABLE, GRANT)
  • Arbitrary DDL/DML execution — executing an untrusted .sql file runs all contained statements, which may DROP tables, INSERT malicious data, create backdoor user accounts, or GRANT elevated privileges
  • Data exfiltration via INTO OUTFILE — MySQL's SELECT INTO OUTFILE writes query results to the server filesystem, potentially leaking sensitive data if an attacker controls the query
  • Stored procedure injection — malicious SQL files can create stored procedures or triggers that execute on future operations, persisting the attack beyond the initial import

الحماية: FileDex displays SQL files as read-only text in the browser. No SQL execution, no database connection, no server-side processing. SQL content is rendered for viewing and format reference only.

DBeaver أداة
Free universal database GUI — connects to MySQL, PostgreSQL, SQLite, Oracle, SQL Server, and 80+ databases
pgAdmin أداة
PostgreSQL administration and development platform with query tool, ERD designer, and monitoring
SQLite CLI أداة
Command-line interface for SQLite — execute queries, import/export CSV, manage databases
Flyway أداة
Database migration tool — version-controls SQL schema changes with numbered migration files
SQLFluff أداة
SQL linter and auto-formatter — enforces consistent style across MySQL, PostgreSQL, BigQuery dialects
Prisma مكتبة
TypeScript ORM with type-safe SQL generation, migrations, and a visual database browser