Changing the schema · Changement de schéma
Changing a table's structure
A table's design is not fixed. ALTER TABLE … ADD adds a new column to an existing table:
Existing rows get NULL in the new column until you fill them in.
Modifier la structure d'une table
La conception d'une table n'est pas figée. ALTER TABLE … ADD ajoute une nouvelle colonne à une table existante :
ALTER TABLE product ADD weight DECIMAL(5, 2);
Les lignes existantes reçoivent NULL dans la nouvelle colonne jusqu'à ce que vous les remplissiez.
Removing a table
DROP TABLE deletes a whole table — its structure and all its rows:
This cannot be undone, so use it with care. Dropping a table that other tables reference can break referential integrity.
Supprimer une table
DROP TABLE supprime une table entière — sa structure et toutes ses lignes :
DROP TABLE product;
Cela ne peut pas être annulé, utilisez-le avec précaution. Supprimer une table à laquelle d'autres tables font référence peut briser l'intégrité référentielle.
Common mistakes
ALTER TABLEadds or changes a column.- Existing rows get NULL in a new column unless you set a default.
Erreurs courantes
ALTER TABLEajoute ou modifie une colonne.- Les lignes existantes reçoivent NULL dans une nouvelle colonne sauf si vous définissez une valeur par défaut.
Add a new column weight of type DECIMAL(5, 2) to the product table using ALTER TABLE. · Ajoutez une nouvelle colonne weight de type DECIMAL(5, 2) à la table product en utilisant ALTER TABLE.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Delete the entire product table with DROP TABLE. (Afterwards only customer and · et orders remain.) · Supprimez la table entière product avec DROP TABLE. (Après, seuls customer et orders restent.)
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.