CRUD operations in SQL refer to the basic actions that are performed on database data. CRUD stands for Create, Read, Update, and Delete. Here’s how they correspond to SQL operations:
- Create: This is about creating new data. In SQL, this is usually done with the `INSERT` statement, which adds new rows to a table.
INSERT INTO table2
(
column1,
column2,
column3,
…
)
SELECT column1,
column2,
column3,
…
FROM table1
WHERE condition;
2. Read: This operation involves reading or retrieving data. In SQL, you use the `SELECT` statement to query data from the database, which can then be read and used.
SELECT column1,
column2,
… from table_name;
3. Update: This operation is used to modify existing data. In SQL, the `UPDATE` statement is used to make changes to the existing records in a table.
UPDATE table_name
SET column1 = value1,
column2 = value2,
…
WHERE condition;
4. Delete: This refers to the removal of data. In SQL, the `DELETE` statement is used to remove records from a table.
DELETE FROM table_name
WHERE CONDITION;
These operations are fundamental to interacting with a relational database using SQL.