CRUD stands for Create, Read, Update, and Delete, and it represents the basic operations that can be performed on data in a relational database.
Create: The Create operation is used to insert new data into a table. It is typically done using the SQL INSERT statement. Here is an example:
INSERT INTO customers (customer_name, email, phone)
VALUES ('John Smith', 'john@example.com', '555-1234')
This statement creates a new customer record in the customers table with the values specified.
Read: The Read operation is used to retrieve data from a table. It is typically done using the SQL SELECT statement. Here is an example:
SELECT * FROM customers
This statement retrieves all records from the customers table.
Update: The Update operation is used to modify existing data in a table. It is typically done using the SQL UPDATE statement. Here is an example:
UPDATE customers
SET email = 'newemail@example.com'
WHERE customer_id = 1
This statement updates the email address of the customer with ID 1 in the customers table.
Delete: The Delete operation is used to remove data from a table. It is typically done using the SQL DELETE statement. Here is an example:
DELETE FROM customers
WHERE customer_id = 1
This statement deletes the customer record with ID 1 from the customers table.
These are the basic CRUD operations in SQL, and they form the foundation of data manipulation in relational databases. By using these operations, you can create, retrieve, update, and delete data in your database to perform a wide range of tasks and operations.