Let's talk about what SQL is and how to use it to work with databases. Even if you are just starting your journey in programming, I will try to make everything clear and visual. Let's figure it out together!

What is SQL?
SQL (Structured Query Language) is a structured query language used to interact with databases. It can be used to add, modify, delete, and retrieve data from a database. SQL is the main tool for working with relational databases such as MySQL, PostgreSQL, SQLite and many others.
Imagine a database as a large table where rows of information are stored. SQL helps you manage this data: add new records, update existing ones, and get the information you need on request.
Basic SQL commands
To use SQL effectively, you need to master a few basic commands. Here are the most important ones:
SELECT: used to retrieve data from a table.
INSERT: adds new data to the table.
UPDATE: updates existing records.
DELETE: deletes data from the table.
Let's look at examples of how to write a simple query to a database.
Example of a simple SQL query
To begin with, let's consider the SELECT command, which allows us to get data. Let's imagine that we have a table named employees that stores employee data. The table might look something like this:
id | name | position | Salary |
|---|---|---|---|
1 | Ivan | Developer | 80000 |
2 | Maria | Manager | 90000 |
3 | Sergey | Designer | 75000 |
Now let's write a simple SQL query to get information about all employees:
SELECT * FROM employees;This query means: "Select all (*) records from the table employees". As a result, you will receive all the information contained in the table.
If you want to select only the names and positions of employees, you can write as follows:
SELECT имя, должность FROM employees;Thus, you will get only two columns: имя and должность.
How to add data to a table
Now let's add a new employee to the table. To do this, use the INSERT command:
INSERT INTO employees (имя, должность, зарплата) VALUES ('Anna', 'Analyst', 85000);This query adds a new entry to the employees table with the specified values for the имя, должность and зарплата fields.
Updating data in the table
The UPDATE command allows you to modify existing data. For example, if we want to change Ivan's salary, we can write the following query:
UPDATE employees SET зарплата = 85000 WHERE имя = 'Ivan';Here we specify that we want to update the зарплата field to a new value, but only for those records where имя is equal to "Ivan".
Data deletion
To delete records, use the DELETE command. For example, to delete an employee named "Sergey":
DELETE FROM employees WHERE имя = 'Sergey';This query will delete the record from the table where the name is "Sergey".
Conclusion
SQL is a powerful tool that makes it easy to manage data in a database. Even simple queries such as SELECT, INSERT, UPDATE and DELETE allow you to work with tables as you need. Mastering SQL opens up great opportunities for you, especially if you work with data or want to become a developer.
If you want to learn more about SQL and try writing queries yourself, I recommend using our application Code. There you will find step-by-step lessons that will help you learn this language from scratch!
