【文章內(nèi)容簡(jiǎn)介】
ng Records Two syntaxes: INSERT INTO Insert one record at a time INSERT SELECT Insert one or more records at a time Inserting Records INSERT INTO Syntax Form 1: Insert whole record. INSERT INTO tablename VALUES(value1, value2, ..., valuen)。 Form 2: Insert partial record. Nonspecified fieldnames are assigned default values. INSERT INTO tablename(field1, field2, ..., fieldn) VALUES(value1, value2, ..., valuen)。 IGNORE You can use the IGNORE keyword between INSERT and INTO to suppress duplicate error messages. Inserting Records INSERT SELECT Syntax Form 1: Insert whole record. INSERT INTO destination_table SELECT field1, field2, ..., fieldn FROM source_tables WHERE conditions。 Form 2: Insert partial record. Nonspecified fieldnames are assigned default values. INSERT INTO destination_table(df1, df2, ..., dfn) SELECT sf1, sf2, ..., sfn FROM source_tables WHERE conditions。 INSERT INTO Example Example: Add Kung Fu Panda into the database. INSERT INTO Movies VALUES(7, 39。Kung Fu Panda39。, 39。2022060639。, 39。G39。, 92, 39。USA39。, 39。English39。, (SELECT CompanyID FROM Companies WHERE Name = 39。Dreamworks Pictures39。))。 INSERT INTO and Subqueries As in the previous example, subqueries in the INSERT mand work, but only if the update table and the subquery table are different. This rule only applies to MySQL, other database management systems may behave differently. INSERT SELECT Example Example: Associate all movies that have ‘The X Files’ anywhere in the title with the romance genre. INSERT IGNORE INTO XRefGenresMovies SELECT MovieID, 39。Romance39。 FROM Movies WHERE Title LIKE 39。%The X Files%39。 Deleting Records Deletes one or more rows from a table Deletes all rows without WHERE condition Two syntaxes SingleTable DELETE Syntax MultiTable DELETE Syntax SingleTable DELETE Syntax Deletes one or more rows from a table Deletes all rows without WHERE condition Syntax: DELETE FROM tablename WHERE conditions。 SingleTable DELETE Syntax Examples: Delete all ratings. Delete all ratings by semory. SingleTable DELETE Syntax Solutions: Delete all ratings. DEL