Apostille SQL Commands
Apostille SQL Commands
To work with back-end programming and, mainly, database administration, it is essential to master the language.
SQL is fundamental. This is because regardless of the language used in your development project, the great...
most systems depend on integration with databases.
And for that, knowing SQL is essential!
SQL (Structured Query Language) is the query language.
standard used in relational databases. Combining this powerful language and the correct use of DBMS
(Relational Database Management System) SQL commands can interact with the database,
performing various tasks such as inserting, editing and deleting records, creating, editing and deleting tables.
But you already knew that, right?
What you may not know is which commands you really NEED to know, how to use them, and in which situations.
situations, especially because there are countless commands and possible combinations, and at the beginning of a career in the field, mastering all of this
it can cause a lot of headaches.
Therefore, below we list the 10 SQL commands that every developer and/or DBA needs to know to do well in the
area!
IMPORTANT:For our examples, we will base ourselves on the SQL language for the MySQL DBMS. Although SQL
to possess a structural pattern among the various existing DBMS (Oracle, PostgreSQL, SQLite, Microsoft SQL Server, MySQL, etc)
small variations in the commands may occur. In other words, at the moment the organization or team chooses one
database Or another, the developer/DBA will need to learn the specifics of the SQL language for the chosen DBMS.
3) USE Command
Similar use to the command above. With the USE command, it is possible to select the database we want.
to use/manipulate. For that, we write the following instruction:
USE exemplos_becode;
From now on, all executed commands will take effect on the chosen database, in this case, the database of
data that we just created, the 'exemplos_becode'.You might be wondering:why use the SHOW command
DATABASES eUSE?
It is simple, imagine a scenario where you work with various databases and need to switch from one to another,
Or rather, to know what is in one database and what is contained in the other. This is the purpose of these commands.
8) UPDATE Command
The UPDATE command is responsible for updating already created data in our table. However, to find the record
What we want to change, we must use a condition. A basic example of a condition is to look for a value already known. For
Example, the product code. Below, we will change the description of the product that has the code 2:
UPDATE products SET description = 'Example product 2' WHERE code = 2;
To update the products table and change the description field, we will use the SET command along with a condition.
WHERE. This combination is also useful when we want to change multiple records with just one command. For example,
The command below changes the description for all items that have a code greater than 1:
UPDATE products SET description = 'Example product'WHERE code > 1;
9) DELETE command
To delete a record from our table, we use the DELETE command along with a condition, following the same
logic used in the UPDATE command. First, let's insert a new record with code 3:
INSERT INTO products VVALUES ("Example 3", 3, "Example product");
In the code below, we will delete the product we just created based on the condition defined in the SQL code:
DELETE FROM products WHERE code = 3;
Just like the UPDATE command, it is possible to remove multiple records at once, using conditions that return
multiple records.