UNIHIVE

Study Hub UNIPORT CSC 282

CSC 282 · Database Programming

Creating, inserting, updating and deleting records

File creation and the four basic operations, validation, and keeping files consistent.

Our notes

2 min read

Creating a file

  1. Design the record layout (fields, types, sizes, key).
  2. Create the empty file (or table) with that structure.
  3. Load the first records, validating each.

The four operations (CRUD)

OperationFile viewSQL
Create (insert)add a recordINSERT
Read (retrieve)find and displaySELECT
Updatechange fields of a recordUPDATE
Deleteremove a recordDELETE

Insertion

  • Sequential file: insertions are sorted and merged during the next master update.
  • Direct file: compute the address, place the record (handle collisions).
  • Always check the key does not already exist.

Updating

Find the record by key, change the fields, write it back. Record who changed it and when for important data.
Two kinds of update:

  • Amendment: change details (a new phone number).
  • Posting: apply a transaction to a balance (a ₦20,000 fee payment reduces the amount owed).

Deletion

  • Logical delete: mark the record (a "deleted" flag) and skip it; it can be restored, and history is kept. dBase marked records with DELETE and removed them only on PACK.
  • Physical delete: remove it from storage. Space is reclaimed, the record is gone.

Business systems often prefer logical deletion or archiving for audit.

Validation checks before storing

  • Presence: required fields not empty.
  • Type: digits where digits are expected.
  • Range: score 0 to 100; level 100 to 600.
  • Format: matric number pattern, e-mail shape.
  • Length: phone number 11 digits in the 0803... form.
  • Lookup: the course code exists in the course file.
  • Check digit: a digit computed from the others catches typing errors (used in ISBNs and account numbers).

Validation checks that data is reasonable; verification checks it was entered as the source says (double entry, reading back).

Worked example: posting payments

Master: student 1001 owes ₦85,000; 1002 owes ₦40,000. Transactions: 1001 pays ₦50,000; 1003 pays ₦10,000.

  • 1001 becomes ₦35,000.
  • 1002 unchanged.
  • 1003 has no master record: write it to an error report, do not create a new student from a payment.

Exams usually ask

  • Explain CRUD and give the matching SQL.
  • Logical versus physical deletion.
  • Name and give examples of validation checks; distinguish validation from verification.

Common mistake

Updating or deleting without first confirming the record exists and is the right one. In SQL, an UPDATE with no WHERE clause changes every row.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 282 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.