Crud Operations in SQL

Abhilash Jose
Abhilash Jose  - Data Science Specialist
3 Min Read

CRUD stands for Create, Read, Update, and Delete—the four fundamental operations performed on databases. Each operation corresponds to a specific SQL query, allowing you to interact with and manipulate data within a relational database. Let’s walk through each one.

1. Create (INSERT)

The Create operation refers to inserting new data into a table. In SQL, this is done using the INSERT INTO statement.

Syntax:

Example:

This adds a new row with the values ‘John’, ‘Doe’, and 30 into the employees table.

2. Read (SELECT)

The Read operation retrieves data from the database. This is accomplished using the SELECT statement. You can retrieve specific columns or all columns from a table.

Syntax:

Example:

This fetches the first_name, last_name, and age columns for all rows in the employees table.

To fetch all columns, you can use the * wildcard:

3. Update (UPDATE)

The Update operation modifies existing data in a table. This is done using the UPDATE statement, which allows you to change the values of one or more columns in a row.

Syntax:

Example:

This changes the age of the employee named John Doe to 31. Always use a WHERE clause to specify which rows to update; otherwise, all rows will be updated.

4. Delete (DELETE)

The Delete operation removes data from the database. The DELETE statement deletes rows from a table based on a condition.

Syntax:

Example:

This deletes the row where the first_name is John and the last_name is Doe. Like UPDATE, always use a WHERE clause to avoid deleting all rows.

CRUD Summary:

  • Create: Insert new records into a table using INSERT.
  • Read: Retrieve data from a table using SELECT.
  • Update: Modify existing data in a table using UPDATE.
  • Delete: Remove data from a table using DELETE.

These four operations form the backbone of interacting with relational databases, allowing you to manage data effectively.

Share this Article
By Abhilash Jose Data Science Specialist
Follow:
Abhilash Jose is a data science specialist from India. He specializes in data analysis and is well-known for his expertise in areas such as machine learning and statistical modeling. His skills encompass a wide range of techniques, including data mining, predictive modeling, and data visualization.
Leave a comment