SQL is a Structured Query Language
SQL is a Structured Query Language
SQL is a structured query language designed to retrieve information from a database. If we describe the scheme of SQL operation in simple words, then the specialist forms a request and sends it to the database. That, in turn, processes this information, “understands” what exactly the specialist needs, and sends a response.
The data is stored in the form of tables, it is structured and laid out in rows and columns to make it easier to operate with them. This way of storing information is called relational databases (from the English relation – “relationships”). The name indicates that the objects in such a database are connected by certain relationships.
What is SQL for?
SQL is not a programming language, so you won’t be able to write an application or a website using it, but at the same time, the internal work of the site (backend) is impossible without queries. Searching for information on Google is also a SQL usage model. The user sets the parameters that interest him and sends a request to the server; then the magic happens and results appear in the search results that match exactly this query.
SQL is used by different types of specialists:
- Analysts and product marketers. Knowledge of SQL helps these specialists not to depend on programmers, but to independently receive and process data.
- Developers and testers. Using SQL, they can independently design databases for fast and reliable work with data, improve websites and applications with their help.
- Heads and managers. SQL will allow specialists in senior positions to independently access databases, control the work of the company and receive real-time data on the state of affairs.
How Requests Work
To understand exactly how the request magic works, let’s imagine its path from the user to the data he needs:
User → Client → Query → Control System → Database → Table with databases
Data for working with SQL is stored in tables. How exactly they are arranged – we will understand below; for now, let’s just imagine them. There are several intermediaries on the way from the user to the table:
- Client – a way to enter a request. In the case of Google, for example, the client would be a browser search bar into which the user enters a formulated query.
- A database management system (DBMS) is a set of programs that allow you to manage data. This system helps the tables understand what the user wants, and the user what the tables answer him.
- A database is a storage system for tables in which they are interconnected. The database itself does not know how to manipulate information – it’s just a repository where each object has its own place.
What is a database in SQL
SQL queries access data in the form of tables, that is, relational databases. A simplified version of such a database is Excel tables, in which information is also organized into columns and rows.
Basic concepts of the relational model:
1. Relationship is the table itself, it is two-dimensional and consists of columns and rows.
2. Attribute – a column in the table that contains one specific parameter: name, type, date, cost or other characteristic.
3. Domain is the valid values for each attribute. For example, in the “Name” or “Name” column, the values must be a set of alphabetic characters, but they cannot begin with “ь” or “ъ” and cannot be written as numbers.
4. A tuple (string or record) is a tabular row with a serial number that contains information about one specific object.
5. Value – an element of the table, which is located at the intersection of columns and rows.
6. The key is the most important column in the table, due to these values, interaction takes place in the relational database, it links the tables together.
Keys are of several types:
- The primary key is an identifier, such as an index or article number.
- A candidate key is another unique value that can serve as an identifier.
- A foreign key is a reference column used to join two tables, each value of the foreign key necessarily corresponds to the primary key in the other table.
Operators help you work with data – certain words or symbols that are used to perform a specific operation – for example, to select from a set by a specific parameter. If we need to sort out those with Parmesan from all types of pizza, we need to use the SELECT statement (selection according to the condition).
Operators in SQL are divided into several groups according to the tasks they solve.
DDL (Data Definition Language) – data definition operators. They work with objects, that is, with entire tables. If the database needs to be supplemented with a table with new data or, conversely, one of the tables with erroneous data needs to be removed, this set of operators is used.