What is a Database?
A database is any organized collection of data. While a spreadsheet or document can store data, it is not ideal for large-scale or structured access.
For example:
Easy: Storing a small list of books in Excel.
Difficult: Managing 100,000 books with authors, publishers, and multiple copies using Excel.
What is a Relational Database?
A Relational Database Management System (RDBMS) organizes data into tables that are connected through relationships. Oracle is one of the most powerful RDBMS platforms.
Table Structure
Table Component | Description |
---|---|
Table | A collection of related data rows |
Row | A single record |
Column | A field that defines data type and label |
Schema | A collection of tables and objects owned by a user |
In Oracle:
A user owns a schema.
Two users can have tables with the same name because ownership is separate.
Why Use Relational Design?
Consider storing data about books and authors in one table. This causes data repetition if an author wrote multiple books.
Instead, normalize the data:
Create a separate
AUTHORS
table.Link it to the
BOOKS
table using a foreign key.
ERD (Entity Relationship Diagram)
To understand how relational databases work, let’s look at a simple example with two tables: AUTHORS
and BOOKS
.
SQL Syntax to Create Tables:
CREATE TABLE authors (
id NUMBER PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50)
);
CREATE TABLE books (
isbn CHAR(10) PRIMARY KEY,
category VARCHAR2(20),
title VARCHAR2(100),
num_pages NUMBER,
price NUMBER,
copyright NUMBER(4),
author1 NUMBER CONSTRAINT books_author1
REFERENCES authors(id)
);
AUTHORS Table
ID | First Name | Last Name |
---|---|---|
1 | John | Smith |
2 | Alice | Brown |
BOOKS Table
ISBN | Category | Title | Num Pages | Price | Copyright | Author ID |
---|---|---|---|---|---|---|
1001 | Tech | Mastering PL/SQL | 350 | 399 | 2023 | 1 |
1002 | Fiction | The Silent Writer | 280 | 299 | 2022 | 2 |
Example Query: JOIN Authors and Books:
SELECT b.title, a.first_name, a.last_name
FROM authors a, books b
WHERE b.author1 = a.id;
This joins the tables on the author1
foreign key, producing output like:
Title | First Name | Last Name |
---|---|---|
Mastering PL/SQL | John | Smith |
The Silent Writer | Alice | Brown |
Benefits of Relational Databases
Feature | Advantage |
---|---|
Redundancy Reduction | No repeated author info for each book |
Data Integrity | Uses primary and foreign keys |
Scalability | Easy to expand with more entities (e.g., Publisher) |
Modularity | Separate logic for each entity (Authors, Books, etc.) |