CRUD operations
CRUD is an acronym that stands for Create, Read, Update, and Delete, which are the four basic operations that can be performed on data in a database.
CRUD operations are fundamental to managing and interacting with data in any database management system (DBMS). Each operation can be related to SQL statements.
-
Create
SQL Statement:
INSERTAdds new data or records to a database.
INSERT INTO employees (first_name, last_name, email) VALUES ('John', 'Doe', 'john.doe@example.com');This statement adds a new record to the employees table with the specified values for first_name, last_name, and email.
-
Read
SQL Statement:
SELECTRetrieves or queries data from a database.
SELECT first_name, last_name FROM employees WHERE department = 'Sales';This statement retrieves the first_name and last_name of employees who work in the Sales department.
-
Update
SQL Statement:
UPDATEModifies existing data within a database.
UPDATE employees SET email = 'j.doe@example.com' WHERE first_name = 'John' AND last_name = 'Doe';This statement updates the email address of the employee named John Doe.
-
Delete
SQL Statement:
DELETERemoves data or records from a database.
DELETE FROM employees WHERE last_name = 'Doe';This statement deletes all records from the employees table where the last_name is Doe.