$devtoolkit.sh/glossary/what-is-sql

What is SQL? — Structured Query Language Explained

Definition

SQL (Structured Query Language) is a domain-specific language for managing and querying relational databases. It is used to create database schemas, insert and modify data, retrieve data with powerful filtering and aggregation, and control access permissions. First standardized in 1986, SQL is implemented by virtually every major database system including PostgreSQL, MySQL, SQLite, SQL Server, and Oracle, each with minor dialect differences.

How It Works

SQL operations are organized into four categories: DML (Data Manipulation Language) for SELECT, INSERT, UPDATE, DELETE; DDL (Data Definition Language) for CREATE, ALTER, DROP; DCL (Data Control Language) for GRANT, REVOKE; and TCL (Transaction Control Language) for COMMIT, ROLLBACK. The SELECT statement is the most powerful: it can filter rows with WHERE clauses, join multiple tables on matching keys, group rows and compute aggregates (COUNT, SUM, AVG), sort results with ORDER BY, and limit result sets with LIMIT/OFFSET.

Common Use Cases

  • Querying and filtering data from relational database tables
  • Joining related tables to assemble complete records from normalized data
  • Aggregating transactional data for reporting and analytics
  • Defining and modifying database schemas during application development
  • Writing database migrations for deployment pipelines

Example

SELECT u.name, COUNT(o.id) AS order_count, SUM(o.total) AS revenue
FROM users u
JOIN orders o ON o.user_id = u.id
WHERE o.created_at > '2024-01-01'
GROUP BY u.id, u.name
HAVING COUNT(o.id) > 5
ORDER BY revenue DESC
LIMIT 10;

Related Tools

FAQ

What is the difference between SQL and NoSQL?
SQL databases store data in structured tables with a predefined schema and enforce relationships with foreign keys. NoSQL databases (MongoDB, Cassandra, Redis) use flexible schemas and different data models (document, key-value, column, graph) optimized for specific access patterns.
What is a SQL injection attack?
SQL injection occurs when user input is interpolated directly into a SQL string without sanitization. An attacker can inject SQL syntax to manipulate queries, exfiltrate data, or destroy tables. The fix is to always use parameterized queries (prepared statements), never string concatenation.
What is the difference between an inner join and an outer join?
An inner join returns only rows that have matching values in both tables. A left outer join returns all rows from the left table and matching rows from the right; unmatched right-side rows get NULL values. A full outer join returns all rows from both tables.

Related Terms

/glossary/what-is-sqlv1.0.0