INSERT INTO nom_table [(attributs)] VALUES (valeurs)
INSERT INTO nom_table [(attributs)] SELECT ...
Par exemple :
INSERT INTO LANG (CODE, LIBELLE) VALUES
('en_US', 'English'),
('fr_FR', 'Français');
Si on essaie d’insérer une clé primaire qui existe déjà, une erreur est levée.
On peut modifier ce comportement avec
INSERT IGNORE
-- Ingore l'insertion si la clé existe déjà
INSERT IGNORE INTO etudiant (id, nom, prenom) VALUES (1, "Dupont", "Manon");
ou en ajoutant une clause DUPLICATE KEY UPDATE ...
:
-- Met à jour la ligne existante avec le nouveau prenom
INSERT INTO etudiant (id, nom, prenom) VALUES (1, "Dupont", "Manon")
ON DUPLICATE KEY UPDATE prenom = VALUES(prenom);
UPDATE nom_table SET attribut = valeur
[WHERE condition]
[ORDER BY attributs]
[LIMIT count]
Voir l’article sur les sélections pour la description de WHERE
, ORDER BY
et LIMIT
Exemples :
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
UPDATE reservedNicknames
SET id = CONCAT('rename - ', id),
nickname = CONCAT('rename - ', nickname)
WHERE LENGTH(nickname) <> 8;
DELETE FROM nom_table
[WHERE condition]
[ORDER BY attributs]
[LIMIT count]
Exemples :
DELETE FROM Customers
WHERE CustomerName = 'Alfreds Futterkiste';
DELETE FROM currencies
WHERE LENGTH(code) != 3;