Data Manipulation Language (DML) Explained
Key Concepts
- INSERT Statement
- UPDATE Statement
- DELETE Statement
INSERT Statement
The INSERT statement is used to add new records into a table. It allows you to specify the values for each column in the new record. The basic syntax is:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Example: To add a new customer with the name "John Doe" and email "john.doe@example.com" into the "Customers" table, you would use:
INSERT INTO Customers (Name, Email) VALUES ('John Doe', 'john.doe@example.com');
Analogies: Think of the INSERT statement as adding a new entry to a guest list or a new item to a shopping cart.
UPDATE Statement
The UPDATE statement is used to modify existing records in a table. It allows you to change the values of one or more columns based on specified conditions. The basic syntax is:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Example: To update the email address of a customer with the name "John Doe" in the "Customers" table, you would use:
UPDATE Customers SET Email = 'john.doe.new@example.com' WHERE Name = 'John Doe';
Analogies: The UPDATE statement is like editing an existing entry in a contact list or updating the details of a product in an inventory.
DELETE Statement
The DELETE statement is used to remove existing records from a table. It allows you to delete one or more rows based on specified conditions. The basic syntax is:
DELETE FROM table_name WHERE condition;
Example: To delete a customer with the name "John Doe" from the "Customers" table, you would use:
DELETE FROM Customers WHERE Name = 'John Doe';
Analogies: The DELETE statement is like removing an entry from a guest list or deleting an item from a shopping cart.