Subtopic Notes

9 Databases

9. Databases

Database Terminologies

  • Database: Organized collection of non-redundant interrelated data stored electronically
  • DBMS (Database Management System): Software that facilitates the creation, maintenance, and manipulation of databases
  • Entity: A distinct object or concept that can be identified and stored in a database, often representing a real-world object
  • Table: A structured arrangement of data in rows and columns within a database, representing entities
  • Record: A single entry in a table, consisting of fields that contain related data about an entity
  • Field/Column/Attribute: Contains specific property about a record
  • Validation: DBMS automatically provides some validation checks to ensure that data comes in the required format. For example range check for age, format check for dates.
  • Primary key: Attribute/s which is the unique identifier
    • Primary fields must have values that are never repeated within the table

Example Database (Vehicle Table)

VINMakeModelYearMileageBodyPrice
TYT1ToyotaPrado202315000SUV55000
HND1HondaVezel202220000Crossover25000
BUG1BugattiVeyron201210000Supercar2200000
HND2HondaCR-V202130000SUV30000
TYT2ToyotaC-HR202025000Crossover22000
LAM1LamborghiniGallardo200840000Supercar150000
ASM1Aston MartinDB12201912000Grand Tourer300000

Examples from the above database:

  • Tables: Vehicle
  • Entity: Vehicle
  • Record: Row 2 to 8
  • Field/Column/Attribute: Make, Model, Year
  • Primary Key: VIN

Data Types:

  • CHARACTER

    Represents one character only

  • Text/Alphanumeric
    Represents a string enclosed in “double quotes”

  • Boolean
    TRUE/FALSE

  • Integer
    A whole number (Maybe +ve, -ve or 0)

  • Real
    A number with decimal

  • Date/Time
    May use string with dd/mm/yyyy format and HH:mm AM/PM format

<Conditions> SQL Operators

OperatorEvaluation
=Equals to
>Greater Than
<Less Than
>=Greater than or equal to
<=Less than or equal to
<>Not equal to
BETWEENBetween a range of two values Eg. BETWEEN '2018-08-01' AND '2018-08-31'
LIKESearching for a patten ‘a%’ Starts with character a ‘a_’ - 1 character after a (Each _ represents 1 character)
IS NULLCheck for null values
ANDMultiple conditions
ORMultiple conditions
NOTSpecify a condition that might be false

Query General Format

SELECT <Fields/Functions separated by ,>
FROM <table-name>
WHERE <conditions separated by AND or OR>
ORDER BY <field-names> ASCENDING/DESCENDING;

SELECT Command

SELECT *: Selects all the records from specified table
SELECT <field-name>: Returns the select field name/names (separated using ,)
SELECT COUNT(<field-name>): Returns no. of field-names
SELECT SUM(<field-name>): Returns sum of field-names