« MySQL/Manipulation de données » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 8 :
VALUES (value1, value2, value3)
</source>
 
Insert one record (values are inserted in the order that the columns appear in the database):
Insérer un enregistrement (les valeurs sont insérées dans l'ordre où les colonnes apparaissent dans la base) :
<source lang=sql>
INSERT INTO TableName
VALUES (value1, value2, value3)
</source>
 
Insert two records:
Deux lignes :
<source lang=sql>
INSERT INTO TableName
Ligne 21 ⟶ 23 :
INSERT INTO antiques (buyerid, sellerid, item) VALUES (01, 21, 'Ottoman');
</source>
 
You can also insert records 'selected' from other table.
Copier ceux d'une autre table :
<source lang=sql>
INSERT INTO table1(field1, field2)
Ligne 29 ⟶ 32 :
INSERT INTO World_Events SELECT * FROM National_Events
</source>
'''Performance tips:'''
 
Astuces de performances :
* To insert many rows, consider using LOAD DATA INFILE instead.
* Pour insérer plusieurs lignes, utiliser <code>LOAD DATA INFILE</code> de préférence.
* If bulk INSERTs are too slow and they operate on indexed non-empty tables, maybe you should increase the value of bulk_insert_buffer_size.
* Si un gros volume d'insertion est trop lent sur des tables indexées non vides, augmenter la valeur de <code>bulk_insert_buffer_size</code>.
* Before performing bulk inserts, you may want to disable thekeys.
* Avant des insertions en masse, retirer les clés.
* LOCKing a table also speeds up the INSERT.
* Verrouiller une table (<code>LOCK</code>) accélère les <code>INSERT</code>.
 
== UPDATE ==
The syntax is:
<source lang=sql>
UPDATE table SET field = newvalue WHERE criteria ORDER BY field LIMIT n
</source>
 
Examples are:
Exemples :
<source lang=sql>
UPDATE owner SET ownerfirstname = 'John'
Ligne 66 ⟶ 69 :
ORDER BY date LIMIT 1
</source>
 
WithAvec <code>ORDER BY</code> you can order the rows before updating them, and only update a given number of rows (LIMIT).
 
It is currently not possible to update a table while performing a subquery on the same table. For example, if I want to reset a password I forgot in SPIP: