What is SQL? How to use?

15

I already know at least that SQL is related to the database, with the query of values in the database.

But it is not clear what would be the SQL. What would you use this resource for? And how do you use SQL, for example in a user system?

    
asked by anonymous 28.06.2014 / 03:44

3 answers

17

Basically basic

The information I'm posting here is basic and may contain errors, anything can edit the answer or comment;)

Brief explanation

SQL is a database language, it has a syntax similar to that of English, if I were to query the Name of the user with ID 2 could have a table like this:

+----+------------------+
| ID | Nome             |
+----+------------------+
| 1  | João Vitor       |
| 2  | Isabela Monteiro |
| 3  | John Snow        |
+----+------------------+

I would tell the SQL server to run the following command in the database:

SELECT Nome FROM 'nomeDaTabela' WHERE 'ID' = 2;

That translating would be:

SELECT COLUMN Nome FROM TABLE nomeDaTabela WHERE ID FOR = 2

So I would select: Isabela Monteiro

Of course, I can do much more than read information, I can insert it, update it, delete it, merge it, and more.

SQL itself is just a syntax, there are several types of servers that interpret SQL, the most famous are MySQL, Postgre and MS SQL (Windows / Microsoft). Some functions and some of the syntax may vary from server to server, but the essence is the same.

Basically the scheme would be:

Meu código -> Declaração SQL (SELECT * FROM blabla) -> Servidor (MySQL)
-> Servidor interpreta e salva no banco de dados

There are several utilities in this, but as the name says, the main goal is to store data in tables in the databases.

Login example

Let's suppose I need a login for my application, here is my user table:

+----+------------------+--------------+
| ID | Nome             | Senha        |
+----+------------------+--------------+
| 1  | João Vitor       | senha1234    |
| 2  | Isabela Monteiro | goLfiNhO0    |
| 3  | John Snow        | uKnowNothing |
+----+------------------+--------------+

Now that I already know my users, I need my basic login system:

First we took the information that the user sent:

Name: João Vitor

Password: password1234

We now compare the information to the database to see if the information the application user sent is correct.

SELECT * FROM 'tabelaUsuarios' WHERE 'Nome'="João Vitor" AND 'Senha'="senha1234"

By default, the server will return the number of rows in the table it encountered, if the number of rows is greater than 0, we know that the login actually exists and we authenticate it. If not, we asked the user to enter the credentials again.

Basic info

I suggest you check link ; is in English but has a good basic tutorial for what you need.

    
28.06.2014 / 04:53
4

SQL is the language you use for querying and inserting into a relational database. Your question is pretty basic and I advise you to study what is Relational Database and try to understand how it works. SQL is not a resource but a language. There are several types of database, SQLite, SQLServer, Oracle all use the SQL language to do the operations.

Useful links for study: link

    
28.06.2014 / 08:06
0

Database Management Systems were created to ensure the persistence, consistency, and integrity of System Data, a solution created around the 1970s and working well for the information I get.

    
28.06.2014 / 13:07