Vote

SQL is a Structured Query Language used to communicate with a database server. We are going to browse all the useful commands in SQL.


SQL databases

First of all, we will access to MySQL on your system and list the different databases already present.

From this view, you will be able to consult different informations, including these two main functions :

List all the tables of the database on which you are connected.

List all the tables of the captured database.

Change the database.

Display the table’s structure contained in a captured database.

In the same way as SHOW COLUMNS, is is also possible to consult the table’s structure of your database :


CREATE

CREATE is mainly used to create your databases and tables :

Do not display error if there is no database

Parameter of auto-incremation of an integer column.

Parameter of definition of the primary key of your table.

Parameter of obligation of value preventing any invalid capture.

Parameter of definition of default value if the provided value is invalid.

It is possible to create a table from the structure of an existing table, therafter we will see in details the element WHERE :


INSERT

INSERT is used to add datas in your tables :

Please note that datas can be added in an order different from one of your table’s structure :


SELECT

SELECT is used to search for datas in your tables :

Parameter of search condition.

Parameter of limit that displays y recordings from recording x.

Parameter to not display duplications.

Parameter of ASC ascending and DESC descending sorting.

It is possible to cumulate different search conditions thanks to comparison operators and AND and OR elements.
All the following comparison operators can be used :

Parameter of research where % replaces strings.

Equal

Not equal

Not equal

Greater than

Less than

Greater than or equal to

Less than or equal to

List of several possible values

Value within a given interval (useful for numbers or dates)

Value is null

Value is not null


UPDATE

UPDATE is used to upgrade datas in your tables.
We can search with the command WHERE just like we can do with the command SELECT :


ALTER

ALTER is used to change a table’s structure, namely, the addition of one or several columns to your table, to change an existing column or to definitely delete it


DROP

DROP is used to definitely delete a database or a table :

Do not display error if there is no database.


DELETE

DELETE is used to permanently delete recordings in the tables of your database or a table.
We operate our research with the command WHERE just like we do with the command SELECT :

Please try to never forget the command WHERE (usual mistake :)), that would lead to the loss of any table’s content.
It is also possible to clear a table and reset the meter auto_increment unlike DELETE :


Categories: DatabaseTutorials

JN Community

Les Ressources, en particulier les tutoriaux, présupposent que l’Utilisateur qui décide de les mettre en œuvre dispose des connaissances, des compétences et de l’expérience nécessaire pour cette mise en œuvre. L’Utilisateur disposant d’une connaissance, compétence et/ou expérience limitée ou insuffisante doit absolument s’abstenir de mettre en œuvre les Ressources par lui-même.
Jaguar Network décline toute responsabilité quant aux conséquences dommageables de la mise en œuvre des Ressources, notamment sur les infrastructures informatiques de l’Utilisateur, de ses commettants ou préposés ou de tout tiers.
Il est précisé en tant que de besoin que toute intervention de Jaguar Network visant à réparer les dommages causés par la mise en œuvre des Ressources par un Utilisateur ne disposant pas des connaissances, compétences et/ou expériences suffisantes sera facturée et fera l’objet d’un devis préalable et d’un bon de commande aux conditions des contrats Jaguar Network en vigueur.

Related Posts

System

Installation of a web server LEMP (Linux, Nginx, MySQL, PHP)

Vote The installation of a server LEMP Linux + Nginx + MySQL + PHP might be more useful and efficient than an Apache (server LAMP). Articles similaires

System

Operating load-balancing with HAproxy

Vote HAproxy is a software allowing Load-Balancing between several web servers by allocating requests in an almost transparent way for the user. Articles similaires

System

10 tips to write efficient scripts on Linux

Vote The shell script is the most simple type of programming you would write on Linux. Moreover, it is a necessary skill to automate your system administration tasks, to develop new simple features, … In Read more…