SQL Notes: INSERT INTO and DELETE Statements
Mini SQL Lesson #5
I am learning SQL through the W3Schools Tutorial. If you want to do exercises and follow along in-browser, please check out the link!
Finally time to learn how to add and delete records in a table!
INSERT INTO [table] (field_1, field_2, ...)
VALUES (value1, value2, ...),
(value3, value4, ...),
(value5, value6, ...);INSERT INTOinserts new records into a table.fieldnames may be omitted if you are enteringvaluesinto all fields of a table. If you enter values only into specific fields, other fields in the record will returnnull.Multiple new records can be added by comma-separating between records.
Example:
INSERT INTO Cars
VALUES ('13954', 'Toyota', 'AE86', '1983', 'White'),
('35000', 'Trans Am', '20000 WR', '2009', 'Yellow' );
INSERT INTO Cars (Make, Model, Color)
VALUES ('Chevrolet', 'Camaro', 'Yellow');
DELETE FROM [table] WHERE conditionDeletes record(s) that meet the specified
conditionWARNING: Include the condition, otherwise you will delete ALL RECORDS on the table.
If you use
DELETE FROMon an entire table, you will delete all records but the table (it's structure, attributes, and indexes) will remain.To delete a table use
DROP TABLE [table].

