Structured Query Language (SQL)
SQL (Structured query language) is a standard language for the creation and manipulation of databases, usually relational databases.
SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987.
Although SQL is an ANSI/ISO standard, there are different versions of the SQL language. However, to be compliant with the ANSI standard, they all support at least the major commands (such as CREATE, SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.
Following the relational model, SQL consists of several parts. It has a structural part, for example, which is designed to create and destroy database objects. This part of the language is generally referred to as a data definition language (DDL). Similarly, it has a functional part for performing operations on those objects (such as retrieving and manipulating data). This part of the language is referred to as a data manipulation language (DML).
Most of the actions you need to perform on a database are done with SQL statements. SQL statements consists of keywords that are easy to understand.
The following SQL statement returns all records from a table named Customers:
SELECT * FROM Customers;
SQL statements
If you were to navigate a large database without SQL, it would take a significantly longer time to find the data you need.
By using the SELECT
statement, you can select data by table and column types. This way, you can instantly pinpoint data sets that meet all requirements of your search rather than spending a lot of time searching manually.
The INSERT
statement allows you to add new information to the tables. Similarly to the SELECT statement, you can choose multiple columns to input your data into.
The DELETE
statement does exactly what it sounds like: it allows you to delete existing records within a table. A DELETE query also allows you to specify rows that should be deleted that match specific conditions.
The CREATE DATABASE
statement is the first step to setting up your database, it is used to create an entirely new database within your database management system. Likewise, CREATE TABLE is used to create a new table once the database has been created.
The UPDATE
statement is used to update one or more records within the database. You can either update all rows at once or use a condition to only alter a subset.
Types of SQL commands
The SQL language can be broken down into four types of SQL commands – DDL, DML, DQL and DCL.
- DDL (data definition language) used to create and modify database objects like tables, users, and indices. (
CREATE DATABASE/TABLE
, among others) - DML (data manipulation language) used to delete, add, and modify data within databases. (
INSERT
,UPDATE
,DELETE FROM
) - DCL (data control language) used to control access to any data within a database.
- DQL (data query language) used to perform queries on the data and find information, and is composed of COMMAND statements only.