Form 4 · Chapter 2

Relational Database Development

After design, we create tables and use the SQL language to insert, search and filter data through queries.

Creating Tables

Once the design is ready, the first development step is to create the tables. We name a table, list its fields, and set the data type of each field (for example text, integer or date). We also set the primary key. In SQL the CREATE TABLE statement is used.

Example

CREATE TABLE Student (
  StudentNo TEXT PRIMARY KEY,
  Name      TEXT,
  Class     TEXT
);

SQL Basics

SQL (Structured Query Language) is the standard language for communicating with a relational database. Three basic statements are:

  • SELECTretrieves or displays data from a table.
  • INSERTadds a new record into a table.
  • WHERE — a clause that filters rows so that only those meeting a condition are shown.

Key idea

SELECT retrieves data, INSERT adds a record, and WHERE filters records according to a given condition.

Queries

A query is a request to obtain specific information from a database. The asterisk * means "all columns". The WHERE clause lets us find only certain records, while ORDER BY sorts the results.

Example

SELECT Name FROM Student
WHERE Class = '4 Bestari';

This query displays the names of only the students in Class 4 Bestari.

Remember

SELECT = retrieve, INSERT = add, WHERE = filter. SELECT * displays all columns.

Stuck on this topic? A verified JomKelas tutor can walk you through it.

Find a verified tutor