Introduction to SQL: What is SQL
?SQL (Structured Query Langue) is a relational database language. It allows:
- Basic creation and tables.
- Add records as rows.
- Base question.
- Update.
- Modifying Table Structure: Adding, Removing Columns .
- Manage database user rights.
The most famous version on the Web is MySQL, a free implementation that is used, in particular, with PHP, but SQL is also the language of many other database programs, including PostgreSQL, Oracle, DB2, Access and SQL Server.
The main orders are:
- CONNECT to connect to the database.
- CREATE a new database or table.
- INSERT to add data.
- SELECT to query the content.
In SQL, you can make procedural programs with iterations and conditions.
The database can be accessed by executing commands, as in PHP, or using visual software, such as phpMyAdmin, running on the server or locally with XAMPP, as well as many other local server programs.
This tutorial will use MySQL with PHP, as well as the phpMyAdmin interface.
Word about SQL injection
Unfortunately, this query suggestions feature can help if you don't take it upon yourself to inject malicious code, which you should be warned about before writing the first line of code.
How does the injection work? This can be explained by example. The user enters text into the form, and we must find this text in the database using the SELECT command, the definition of which we will see in the textbook.
Suppose the user enters the word "orange." A command built with form data will have this form.
SELECT * FROM stock WHERE fruit = orange
This line will look for what is like orange in the stock of fruits. Now suppose the user enters the following text:
"orange DROP stock."
Here is a new request:
SELECT * FROM stock WHERE fruit = orange; DROP stock
A handler that interprets commands based on keywords that are in the query will find the DROP command and clear the stock table. This is SQL injection. To prevent such attacks, data is always placed in simple quotes:
SELECT * FROM stock WHERE fruit = '$data'
Quotation marks indicate that data is interpreted as data, not commands.
Universal language
SQL commands are close to natural language, this was the goal of the language, the principles of which were laid down by Edgar F. Codd, and taken by IBM in SEQUEL (Structured English Query Language), later renamed SQL. However, the first commercial version based on SEQUEL was Relational Software, which has become since Oracle.
The ISO SQL-92 or SQL-2 standard was defined in 1992 and is widely used.
However, it was replaced by new standards, which must be implemented on all software products.
The ISO standard allows SQL:2006 to manage XML files, including importing XML data into a database or exporting its contents to XML.
These are primarily those norms that matter. Regardless of the software used, MySQL (or MariaDB), PostgreSQL or Oracle, or even managers speak NoSQL like Cassandra, we will find the same syntax, with minor differences.