What Is SQL?
Table of Contents
What is SQL
SQL, or Structured Query Language, is a programming language used to talk to databases. With SQL, you can store, manipulate, and retrieve data from relational databases.
What Can You Do with SQL
- Retrieve data from a database.
- Filter and sort data from a database.
- Perform computations on database data.
- Insert records into a database.
- Update existing records in a database.
- Delete records from a database.
- Create new databases.
- Create new tables in a database.
- Set permissions on databases, tables, and other objects.
Question: What is SQL?
SQL (Structured Query Language) is a programming language for managing relational databases. It enables the storage, retrieval, updating, entry, and analysis of data in tables. This makes SQL essential for data management and analysis tasks.
Components of a SQL System
Database
A database is an organized collection of data stored on a computer. Databases allow to efficiently store, retrieve, and manage information.
Table
A table is a structure within a database that stores data in rows and columns. Each row represents a specific object and each column stores a particular type of data related to that object. As an example, you could have a books
table. In this table, the books are stored as row items, and the columns represent the attributes of each book such as its ID number, title, author, price, etc.
Record
A record in an SQL database is a single row within a table, representing a complete set of related data fields for an entity.
Query
A query is a command written in Structured Query Language (SQL) that's used to retrieve, filter, combine, manage, or manipulate data in a database.
View
A view a virtual table that represents the result of a stored SQL query. It does not store data itself, but it dynamically displays data from other tables. A view simplifies complex queries, controls access to data, and enhances data security.
Popular SQL Databases
Popular SQL databases are PostgreSQL, MySQL, Microsoft SQL Server, Oracle, MariaDB.
Many non-relational technologies also adopt SQL-like querying capabilities, such as Google BigQuery, Amazon Redshift, Snowflake, and Azure Cosmos DB, enabling users to leverage SQL syntax for managing and analyzing diverse data structures like JSON and big data.
History of SQL
The idea of the relational database was introduced in 1970 by Edgar Frank (Ted) Codd, an English computer scientist at IBM. His colleagues Donald D. Chamberlin and Raymond F. Boyce introduced the Structured English Query Language in 1974. The language was based on English structures and used the acronym SEQUEL. To avoid trademark violations, they had to rename it to Structured Query Language, abbreviated as SQL.
Despite the popularity of the language, there is still no agreement on how to pronounce its name: S.Q.L. ("ess-cue-ell") or "sequel." There are many debates on this issue all over the Internet, and while "sequel" usually gets the most votes, Donald D. Chamberlin, co-developer of SQL, and many other SQL gurus prefer "ess-cue-ell."
SQL Commands
The SQL syntax is based on the English language. You can read SQL commands just like ordinary English sentences.
Standard SQL commands are:
SELECT
to retrieve data from a database.INSERT
to add new records into a database.UPDATE
to modify records in a database.DELETE
to remove data from a database.
SELECT
SELECT
is used to retrieve data from a table.
Imagine we run a small bookshop. The books
table stores information about the books we have for sale. We want to get information about all books published before 2010. We want to see the book titles, authors, and publication years. Here's the SQL query to get this data:
SELECT title, author, year FROM books WHERE year < 2010;
You request title
, author, and year from the books
table for the records where the publication year is before 2010. You probably understood this query even without any prior exposure to SQL. This simple syntax is what makes SQL so attractive to new data professionals.
The best way to learn SQL is our interactive SQL Basics course with over 120 hands-on practice exercises.
INSERT
INSERT
is used to add new records to a table. This command inserts "To Kill a Mockingbird" by Harper Lee into table books
:
INSERT INTO books (id, title, author, year) VALUES (17, 'To Kill a Mockingbird', 'Harper Lee', 1960);
UPDATE
UPDATE
is used to modify records to a table. This command modifies the book with ID 17 and sets a new title, author, and year:
UPDATE books SET title = '1984', author = 'George Orwell', year = 1949 WHERE id = 171;
DELETE
DELETE
is used to remove data from a table. This command removes book with ID 17 from the table books
:
DELETE FROM books WHERE id = 17;
Learn this and other syntax nuances from our 2-page SQL Basics Cheat Sheet. It demonstrates with examples how to write different clauses and filtering conditions in SQL.
SQL Dialects
SQL became a standard of the American National Standards Institute (ANSI) in 1986 and the International Organization for Standardization (ISO) in 1987. While no database fully implements the standard, most are very close. There are many versions of the SQL language used with different relational database management systems (RDBMS). The most popular ones are Oracle, MySQL, Microsoft SQL Server, PostgreSQL, and SQLite.
Frequently Asked Questions about SQL
What is SQL Server
SQL Server, or Microsoft SQL Server, is a widely used relational database management system by Microsoft. It is one of many SQL databases available on the market.
What is MySQL
MySQL is another popular relational database management system. It is open-source and one of many SQL databases available today.
What is NoSQL
NoSQL is an umbrella term for data technologies that differ from traditional relational databases, which store data in tables. These databases store data in formats such as key-value pairs, documents, column families, or graphs. Many NoSQL technologies still support SQL as one of their query languages.
Time to Learn SQL!
I recommend the SQL Basics course for those who are just starting their SQL journey. After completing this course, you'll know how to combine information from multiple tables, how to set complex filtering conditions, how to create simple reports by using aggregate functions, and much more.
Thanks for reading, and happy learning!