What is SQL? How to use?

Asked

Viewed 1,209 times

15

I already know at least that SQL has relation with database, with the query of values in database.

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

3 answers

17


Basic

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

Brief explanation

SQL is a language for database, it has a syntax similar to English, if I were for example to consult the Name user with ID 2 I 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 THE COLUMN Nome TABLE nomeDaTabela WHERE THE 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 already says, the main goal is to store data in tables in databases.

Example of login

Let’s assume I need a login for my app, here’s my user table:

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

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

First we get the information the user sent:

Name: João Vitor

Password: password 1234

Now we compare the information with the database to check if the information the application user sent is correct.

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

The server, by default, will return the number of rows in the table you found with this condition, if the number of rows is greater than 0, we know that the login actually exists and we authenticate it. If not, we ask the user to enter the credentials again.

Basic info

I suggest you check http://www.w3schools.com/sql/; is in English but has a good basic tutorial for what you need.

  • How I would use this resource in C#. NET?

4

SQL is the language you use to make queries and insertions in relational databases. Your question is quite 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 various types of database, Sqlite, Sqlserver, Oracle all use SQL language to do operations.

Useful links for study: http://en.m.wikipedia.org/wiki/SQL

0

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.