TD7 : Création et édition de tables

Utilisation de SQLite

On utilisera le site https://sqliteonline.com/

Création de table

CREATE TABLE Tab( attribut1 INT, attribut2 TEXT, attribut3 INT NOT NULL, attribut4 INT PRIMARY KEY )

Supprimer une table

DROP TABLE nom_table

Rajouter des valeurs

INSERT INTO Tab VALUES (0,"test"), (2,2020)

Rajouter une clef étrangère

A la création de la table il faut rajouter :

FOREIGN KEY(attribut) REFERENCES AutreTab(autre_attribut)

Pour SQLite il faut lancer cette commande avant d'utiliser les clefs étrangères :

PRAGMA foreign_keys = ON;

Suppression en cascade

FOREIGN KEY(attribut) REFERENCES AutreTab(autre_attribut) ON DELETE CASCADE

Restriction de suppression

FOREIGN KEY(attribut) REFERENCES AutreTab(autre_attribut) ON DELETE RESTRICT