Skip to main content

11.1 - CRUD Operations and Data Validation

Introduction to CRUD Operations

CRUD stands for Create, Read, Update, Delete. These are the four basic operations you can perform on a database.

The Create operation adds new records to a table. This is the process of inserting data into the database.

The Read operation retrieves data from a table. This allows you to query the database and fetch information.

The Update operation modifies existing records in a table. This involves changing the data that is already stored.

The Delete operation removes records from a table. This is the process of deleting data from the database.


Importance of Data Validation

Data validation ensures the accuracy and quality of data before it is processed and stored in the database. It helps prevent errors, maintain data integrity, and ensure that the data conforms to predefined rules. There are many types of data checks and the following are some of the most common ones you might run into.

Types of Data Checks

1. Format Check

  • Ensures the data is in the correct format.
  • Example: Validating an email address format.

2. Range Check

  • Ensures the data falls within a specified range.
  • Example: Age must be between 0 and 120.

3. Presence Check

  • Ensures that mandatory fields are not left blank.
  • Example: A customer record must have a name and email.

4. Length Check

  • Ensures the data does not exceed a specified length.
  • Example: A phone number must be exactly 10 digits.

5. Uniqueness Check

  • Ensures the data is unique in the database.
  • Example: Each customer email must be unique.

6. Consistency Check

  • Ensures the data is consistent with related data.
  • Example: An order date must be on or after the customer registration date.

7. Data Type Check

  • Ensures the data is of the correct type.
  • Example: The sales amount must be a float instead of a string.

8. Code Check

  • Ensures the data is from a correct/allowed source of values.
  • Example: The provided zip code must be a valid one.