Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
les_fiches_revisions:bases_de_donnees:sql [2021/12/26 19:02] ma [V. Résumé] |
les_fiches_revisions:bases_de_donnees:sql [2023/01/18 10:27] (Version actuelle) hk ancienne révision (2022/01/08 16:43) restaurée |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
======Langage SQL : requêtes d’interrogation et de mise à jour d’une base de données====== | ======Langage SQL : requêtes d’interrogation et de mise à jour d’une base de données====== | ||
+ | Si vous ne comprenez pas le résumé, cliquez sur la commande qui vous conduira a sa page sur ce wiki. | ||
- | [[les_fiches_revisions: | ||
- | =====I. Création d'une base de donnée (sur DB Browser for SQLite)===== | + | =====I. Résumé===== |
+ | |||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | CREATE TABLE nom | ||
+ | (attribut1 domaine1, attribut2 domaine2); | ||
+ | </ | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | SELECT attributs | ||
+ | FROM table1 | ||
+ | </ | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | SELECT DISTINCT attribut | ||
+ | FROM nom_table | ||
+ | </ | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | WHERE condition | ||
+ | |||
+ | WHERE condition1 AND condition2 | ||
+ | |||
+ | WHERE condition1 OR condition2 | ||
+ | </ | ||
+ | |||
+ | Rappel: Les // | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | ORDER BY attribut | ||
+ | |||
+ | ORDER BY attribut1, attribut2 | ||
+ | |||
+ | ORDER BY attribut DESC | ||
+ | </ | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | SELECT attributs | ||
+ | FROM table1 | ||
+ | INNER JOIN table2 ON table1.attribut = table2.attribut | ||
+ | </ | ||
+ | |||
+ | **SELECT complexe** - Exemple | ||
+ | <code sql> | ||
+ | SELECT attributs | ||
+ | FROM table1 | ||
+ | INNER JOIN table2 ON table1.attribut = table2.attribut | ||
+ | WHERE condition1 AND (condition2 OR condition3) | ||
+ | ORDER BY table1.attribut, | ||
+ | </ | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | INSERT INTO nom_table | ||
+ | (attribut1, attribut2, attribut3) | ||
+ | VALUES | ||
+ | (" | ||
+ | </ | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | UPDATE nom_table | ||
+ | SET attribut1=" | ||
+ | WHERE condition | ||
+ | </ | ||
+ | |||
+ | [[les_fiches_revisions: | ||
+ | <code sql> | ||
+ | DELETE FROM nom_table | ||
+ | WHERE condition | ||
+ | </ | ||
+ | |||
+ | |||
+ | =====II. Création d'une base de donnée (sur DB Browser for SQLite)===== | ||
- Allumez //DB Browser for SQLite// | - Allumez //DB Browser for SQLite// | ||
Ligne 39: | Ligne 118: | ||
- | =====II. Créer une relation===== | + | =====III. Créer une relation===== |
**CREATE TABLE** est la commande qui permet de créer un relation, en lui attribuant des attributs et leur domaine | **CREATE TABLE** est la commande qui permet de créer un relation, en lui attribuant des attributs et leur domaine | ||
Ligne 64: | Ligne 143: | ||
- | =====III. Visualiser une relation===== | + | =====IV. Visualiser une relation===== |
Ligne 389: | Ligne 468: | ||
- | =====IV. Modifier une relation===== | + | =====V. Modifier une relation===== |
====A) INSERT==== | ====A) INSERT==== | ||
Ligne 422: | Ligne 501: | ||
</ | </ | ||
- | Cela rajoutera à la relation ceci (visible grace à [[les_fiches_revisions: | + | Cela rajoutera à la relation ceci (visible grace à [[les_fiches_revisions: |
^ id ^ prenom | ^ id ^ prenom | ||
| 1 | | 1 | ||
Ligne 455: | Ligne 534: | ||
Scénario: L' | Scénario: L' | ||
- | Si la relation ABONNEMENT ressemblait à ceci (visible grâce à : [[les_fiches_revisions: | + | Si la relation ABONNEMENT ressemblait à ceci (visible grâce à : [[les_fiches_revisions: |
^ id ^ nom ^ prix ^ durée_mois | ^ id ^ nom ^ prix ^ durée_mois | ||
| 1 | | 1 | ||
Ligne 494: | Ligne 573: | ||
Scénario: Le client //Jean Simon// n'a pas renouvelé son abonnement donc il est supprimé de la relation | Scénario: Le client //Jean Simon// n'a pas renouvelé son abonnement donc il est supprimé de la relation | ||
- | Si la relation ABONNEMENT ressemblait à ceci (visible grâce à : [[les_fiches_revisions: | + | Si la relation ABONNEMENT ressemblait à ceci (visible grâce à : [[les_fiches_revisions: |
^ id ^ prenom | ^ id ^ prenom | ||
| 1 | | 1 | ||
Ligne 525: | Ligne 604: | ||
| 10 | | | 10 | | ||
- | |||
- | =====V. Résumé===== | ||
- | |||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | CREATE TABLE nom | ||
- | (attribut1 domaine1, attribut2 domaine2); | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | SELECT attributs | ||
- | FROM table1 | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | SELECT DISTINCT attribut | ||
- | FROM nom_table | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | WHERE condition | ||
- | |||
- | WHERE condition1 AND condition2 | ||
- | |||
- | WHERE condition1 OR condition2 | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | ORDER BY attribut | ||
- | |||
- | ORDER BY attribut1, attribut2 | ||
- | |||
- | ORDER BY attribut DESC | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | SELECT attributs | ||
- | FROM table1 | ||
- | INNER JOIN table2 ON table1.attribut = table2.attribut | ||
- | </ | ||
- | |||
- | **SELECT complexe** | ||
- | <code sql> | ||
- | SELECT attributs | ||
- | FROM table1 | ||
- | INNER JOIN table2 ON table1.attribut = table2.attribut | ||
- | WHERE condition1 AND (condition2 OR condition3) | ||
- | ORDER BY table1.attribut, | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | INSERT INTO nom_table | ||
- | (attribut1, attribut2, attribut3) | ||
- | VALUES | ||
- | (" | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | UPDATE nom_table | ||
- | SET attribut1=" | ||
- | WHERE condition | ||
- | </ | ||
- | |||
- | [[les_fiches_revisions: | ||
- | <code sql> | ||
- | DELETE FROM nom_table | ||
- | WHERE condition | ||
- | </ |