Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views2 pages

Apostille SQL Commands

The document outlines the importance of mastering SQL commands for database administration and development. It lists ten essential SQL commands, including CREATE DATABASE, SHOW DATABASES, USE, CREATE TABLE, and SELECT, providing brief explanations and examples for each. The document emphasizes that understanding these commands is crucial for beginners in the field and encourages further learning through additional resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Apostille SQL Commands

The document outlines the importance of mastering SQL commands for database administration and development. It lists ten essential SQL commands, including CREATE DATABASE, SHOW DATABASES, USE, CREATE TABLE, and SELECT, providing brief explanations and examples for each. The document emphasizes that understanding these commands is crucial for beginners in the field and encourages further learning through additional resources.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MOST IMPORTANT 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.

1) CREATE DATABASE command


Command that creates an empty database. In the example below, we will create a database called
examples_becode:
CREATE DATABASE exemplos_becode;

2) SHOW DATABASES command


Used in case you have multiple databases and want to view a list of items from each database. For this,
the following command is used:
SHOW DATABASES;

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.

4) CREATE TABLE command


Relational databases store all their data in tables. However, how do we create a table? For this,
we use the CREATE TABLE command:
CREATE TABLE products (name VARCHAR (255), code INT (11));
The tables are divided into columns. In the example above, the products table was set with a column to save the
product name and another column to save the code of each product. Whenever we create a table, we need to specify
which columns and what types of data each column will receive, as we did above.
The data types are diverse and can be accessed at this link. The table will be created within the selected database.
previously. In this case, the bank examples_becode.

5) SHOW TABLES command


Similar to the SHOW DATABASES command, used if you have multiple tables within a database and
want to see a list of all items contained in each table. To do this, use the command:
SHOW TABLES;

6) ALTER TABLE command


The ALTER TABLE command is used to modify an already created table. With it, it is possible to change the structure of
its columns, as well as, add, edit and remove. In the following example, we will add a description column for
our products, right after the code column:
ALTER TABLE products ADD description VARCHAR (255) AFTER code;
7) INSERT Command
Now that we have assembled and changed the structure of a table, we will insert data through SQL commands.
Meanwhile, this can also be done dynamically, within an application, using some programming language.
of back-end programming. With a programming language, it is possible to send SQL commands to the database. From
in any case, let's return to our example:
To add a product to our table, we can insert it as follows:
INSERT INTO products VALUES ('Example', 1, 'Example product');
To insert only specific fields, it is necessary to specify the columns that will receive the values. For example:
INSERT INTO products (name, code) VALUES ('Example 2', 2);
The first form will only work if we fill in all the columns in the correct order. That is, if the table contains 20
Fields, we will have to define the 20 values in the correct order when writing the insertion command.

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.

10) SELECT Command


It is one of the most important SQL commands! It returns records from the database based on conditions.
The conditions follow the same format as the previous commands. To return the product with code 1, we will use the
command:
SELECT * FROM products WHERE code = 1;
The asterisk (*) indicates that we want to return all columns of the item. If we want to, for example, return only the name
of the product, we will use the command:
SELECT name FROM products WHERE code = 1;
We can search for multiple records:
SELECT name FROM products WHERE code >= 1;
Or even all the records from the table, removing the condition:
SELECT name FROM products;

Want to know more?


Obviously, this is not everything! Database Administration is something that requires a lot of study and practice, but it is already
a beginning is an excellent beginning, because at the start of professional practice as a DBA or developer, we encounter
various commands without knowing what exactly each instruction really does.
However, if you actually learn these 10 commands and know how to use them, your life as a beginner DBA will be much
simpler. We hope that this post has helped in this regard!
If you think this is not enough and you need more knowledge by yesterday! Access our course
complete database and SQL language, in it you will notice even more the power and variety of features that the
SQL language has, in order to meet your database and application integration needs!

You might also like