Vous êtes sur la page 1sur 1

Aide-mémoire SQL

Création d’une table :


Jointure
CREATE TABLE [schéma.]nomTable
( colonne1 type1 [DEFAULT valeur1] [NOT
NULL] SELECT table1.column, table2.column
[, colonne2 type2 [DEFAULT valeur2] [NOT FROM table1
NULL] ] [NATURAL JOIN table2] |
[CONSTRAINT nomContrainte1
[JOIN table2 USING (column_name)] |
typeContrainte1]…) ;
[JOIN table2
ON (table1.column_name =
table2.column_name)]|
[LEFT|RIGHT|FULL OUTER JOIN table2
Quatre types de contraintes sont possibles : ON (table1.column_name =
table2.column_name)]|
CONSTRAINT nomContrainte [CROSS JOIN table2];
• UNIQUE (colonne1 [,colonne2]…)
• PRIMARY KEY (colonne1 [,colonne2]…)
• FOREIGN KEY (colonne1 [,colonne2]…)
REFERENCES [schéma.]nomTablePere CLAUSE ORDER BY
(colonne1 [,colonne2]…)
[ON DELETE { CASCADE | SET
NULL }] ORDER BY exp1 [DESC], exp2 [DESC],
• CHECK (condition) ...

Insertion
Fonctions de groupes : AVG, COUNT,
INSERT INTO [schéma.] { nomTable |
nomVue | requêteSELECT } MAX, MIN, SUM
[(colonne1, colonne2…)]
SELECT [column,]
VALUES (valeur1 | DEFAULT, valeur2 |
group_function(column), ...
DEFAULT…); FROM table
[WHERE condition]
Modification [GROUP BY column]
[HAVING condition_logique]
UPDATE table [ORDER BY column];
SET col1 = exp1, col2 = exp2, ...
WHERE condition
Quelques fonctions sur chaînes de
Ou caractères
UPDATE table UPPER(chaîne) Miniscule vers majuscule
SET (col1, col2,...) = (SELECT ...) LOWER(chaîne ) le contraire
WHERE condition LENGTH(ch ) longueur d’une chaîne
TRIM (ch) efface les espaces au début
Suppression et à la fin de ch
DELETE FROM table
WHERE condition Opérations ensemblistes

Syntaxe générale d’une interrogations SELECT …


SQL
OPERATION_ENSEMBLISTE
SELECT ...
FROM ...
SELECT …
WHERE ...
GROUP BY ...
HAVING ... Avec OPERATION_ENSEMBLISTE
ORDER BY ...
= UNION , INTERSECT OU MINUS
La clause SELECT
SELECT [DISTINCT] *
ou
SELECT [DISTINCT] exp1 [[AS] nom1 ],
exp2 [[AS] nom2 ], .....

Vous aimerez peut-être aussi