SQL Flashcards

1
Q

Caractéristiques SQL (5)

A
  • Assure indépendance des données
  • Langage déclaratif
  • Mode interactif ou programmé
  • instruction SQL = requête, résultat = table
  • 3 sous-ensembles : LDD, LCD, LMD
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

LDD (2)

A

Langage de définition de données :

  • CREATE TABLE table (colonne type, colonne type);
  • CREATE VIEW vue AS SELECT att1, att2 FROM table WHERE… ;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

LDD attributs

A

Typés :

  • bigint, int, smallint, tinyint, boolean
  • float, real, double, decimal, numeric
  • char, varchar, time, interval, money, images…
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

LDD CI colonne (5)

A

Contraintes d’intégrité colonne :

  • PRIMARY KEY
  • NOT NULL
  • UNIQUE
  • REFERENCE table(attributs) ON DELETE SET null/cascade
  • CHECK (condition)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Contrainte d’intégrité

A

Règle définissant la cohérence des données de la BDD.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

LDD CI table (4)

A

Contraintes d’intégrité table :

  • PRIMARY KEY (attributs)
  • UNIQUE (attributs)
  • FOREIGN KEY (attributs) REFERENCE table(attributs)
  • CHECK (condition)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

LDD Suppression objet

A

DROP TABLE table;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

LDD Modification table

A

ALTER TABLE table DROP/MODIFY/ADD (colonne);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

LCD

A

Langage de contrôle de données

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

LCD Création compte utilisateur

A

CREATE USER ‘utilisateur’ IDENTIFIED BY ‘mdp’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

LCD attribution de droits

A

GRANT droits ON table TO ‘utilisateur’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

LCD droits (6)

A

ALL PRIVILEGES, SELECT, INSERT, DELETE, UPDATE, ALTER

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

LCD suppression de droits

A

REVOKE droits ON table FROM ‘utilisateur’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

LMD

A

Langage de manipulation des données

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

LMD insertion

A

INSERT INTO table (col1, col2) VALUES (val1, val2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

LMD insertion/copiage

A

INSERT INTO table1 (col1, col2) SELECT FROM (col5, col7) FROM table2;

17
Q

LMD Mise à jour

A

UPDATE table SET col=val (WHERE …);

Possibilité de faire col=col/2…

18
Q

LMD Suppression

A

DELETE FROM table (WHERE …);

19
Q

LMD Interrogation

A

SELECT */col1, col2 FROM table1, table2 WHERE … ;

20
Q

LMD jointure naturelle

A

SELECT */col FROM table1 NATURAL JOIN table2 [USING(col1, col2) pour filtrer]
Avantage pas de ON, nom/domaine colonnes identiques

21
Q

LMD jointure interne

A

SELECT * FROM table1 INNER JOIN table2 ON table1.col1 = table2.col2;

22
Q

LMD jointure externe

A

SELECT * FROM table1 LEFT/RIGHT/FULL/OUTER JOIN table2 ON table1.col1 = table2.col2 (permet de mettre à NULL les colonnes non concordantes sans les perdre).

23
Q

LMD Agrégats définition

A

Partitionnement d’une table en sous-tabes en fonctions des valeurs d’un ou plusieurs attributes, suivi de l’application d’une fonction de calcul à chaque attribut des sous-tables obtenues.

24
Q

LMD Agrégats usage

A

SELECT col1, agrégat(col2) FROM table WHERE (…) GROUP BY col1 HAVING agrégat(col2)>10;

25
Q

LMD Agrégats liste

A

AVG COUNT MAX MIN SUM VARIANCE

26
Q

LMD Ordre

A

à la fin : ORDER BY col

27
Q

LMD utilisation d’un select en condition

A

…WHERE col1

28
Q

SQL union

A

SELECT col FROM tab UNION SELECT col FROM tab

29
Q

SQL différence

A

SQL1 : SELECT col FROM tab WHERE col NOT IN (SELECT col FROM tab2);
SQL2 : SELECT col FROM tab EXCEPT SELECT col FROM tab2;

30
Q

SQL intersection

A

SELECT col FROM tab INTERSECT SELECT col FROM tab

31
Q

Condition plus grand que TOUS

A

SELECT col FROM tab WHERE col > ALL(SELECT col FROM tab WHERE col=val);