Structured Query Language
SQL comes from Structured Query Language. SQL is a tool that database analysts, administrators and developers use to access and manipulate databases. SQL is a computer language that you can use to interact with a relational database. It is a complete language to control and interact with database management systems.

The following SQL statement creates a database called «TVProgrammes»:
CREATE DATABASE TVProgrammes;
The data used by the SQL database are based on three types of data, such as:
- Binary.
- Bit.
- Byte.
- Counter.
- Currency.
- Datetime.
- Single.
- Double.
- Short.
- Long.
- Longtext.
- Longbinary.
- Text.
The CREATE TABLE statement is responsible for creating a table within the database.
CREATE TABLE Programmes( ID int NOT NULL AUTO_INCREMENT, Title varchar(255) NOT NULL, Genere varchar(255) NOT NULL, Duration int, PRIMARY KEY (ID) );
The INSERT statement allows you to create or insert new records in a table:
INSERT INTO Programmes(ID , Title, Genere, Duration) values (1 , 'The Walking Dead' , 'Fantasy' , 60);
The SELECT statement is used to select all data from the database, we can also use filters changing * by the name of a field.
SELECT * FROM Programmes;
We can create more complex sentences using the WHERE clause.
SELECT Title FROM Programmes WHERE Duration BETWEEN 50 AND 100;

The UPDATE statement allows you to update records in a table. We must therefore indicate which records we want to update through the WHERE clause, and which fields through the SET clause, in addition we must indicate which new data will save each field.
UPDATE Programmes set Duration = 120 WHERE Title = ‘X Factor’;
The DELETE statement allows deleting records from a table, its syntax is simple, since we only have to indicate which records we want to eliminate using the WHERE clause.
DELETE FROM Programmes WHERE Duration < 60;
The WHERE clause can be combined with AND, OR, and NOT operators. The AND and OR operators are used to filter records based on more than one condition.
If the two conditions separated by AND are TRUE, the sentence will be true and the condition will be fulfilled.
- The OR operator shows a record if any of the conditions separated by OR is TRUE.
- The NOT operator will display a query if the condition is not true.
In the SQL language it is possible to use functions already defined as:
- MIN();
- MAX();
- COUNT();
- AVG();
- SUM();
SELECT MAX(Duration ) FROM Programmes;



Publicar comentario