3-3-2 Data Manipulation Language (DML) Explained
Key Concepts
- INSERT
- UPDATE
- DELETE
INSERT
The INSERT command is used to add new records into a table. You specify the table name and the values you want to insert into the new record. This command is essential for populating a database with new data.
Example: To add a new student with the name "John Doe" and a grade of "A" into the "Students" table, you would use the following SQL command:
INSERT INTO Students (Name, Grade) VALUES ('John Doe', 'A');
Analogy: Think of INSERT as adding new items to your grocery list. Each time you remember something you need, you add it to the list.
UPDATE
The UPDATE command is used to modify existing records in a table. You specify the table name, the columns you want to update, and the new values. You can also use conditions to specify which records should be updated using the WHERE clause.
Example: To update the grade of a student named "John Doe" to "B" in the "Students" table, you would use the following SQL command:
UPDATE Students SET Grade = 'B' WHERE Name = 'John Doe';
Analogy: Think of UPDATE as changing items on your grocery list. If you decide you no longer need apples but want oranges instead, you update the list accordingly.
DELETE
The DELETE command is used to remove records from a table. You specify the table name and use conditions to specify which records should be deleted using the WHERE clause.
Example: To delete the record of a student named "John Doe" from the "Students" table, you would use the following SQL command:
DELETE FROM Students WHERE Name = 'John Doe';
Analogy: Think of DELETE as removing items from your grocery list. If you decide you no longer need bread, you remove it from the list.
Conclusion
Understanding these three SQL commands—INSERT, UPDATE, and DELETE—is fundamental for interacting with databases. They allow you to add, modify, and remove data, respectively, making your database management tasks more efficient and effective.