CBSE 12th Unit 3-Chapter -2 DATABASE MANAGEMENT AND DATABASE CONCEPTS

                                                                         CHAPTER -2

Relational Data Model

The Relational Data Model is the foundation of most modern database systems. It represents data in the form of tables, which are made up of rows and columns.

Key Concepts:

  • Relation: A table representing a set of related entities.
  • Attribute: A column in a relation that represents a specific property of the entity.
  • Tuple: A row in a relation, representing a single instance of the entity.
  • Domain: The set of possible values that an attribute can take.
  • Degree: The number of attributes in a relation.
  • Cardinality: The number of tuples in a relation.

Keys

  • Candidate Key: A unique identifier for a tuple within a relation. A relation can have multiple candidate keys.
  • Primary Key: One of the candidate keys chosen to uniquely identify each tuple.
  • Alternate Key: Any candidate key that is not chosen as the primary key.
  • Foreign Key: An attribute in one relation that references the primary key of another relation, establishing a link between the two tables.

Diagram: Example of a Relation



 

representing a Students relation with attributes: StudentID, FirstName, LastName, Age, Class

Code Example (SQL)

SQL

-- Create a table with a primary key

CREATE TABLE Students (

    StudentID INT PRIMARY KEY, -- Primary Key

    FirstName VARCHAR(50),

    LastName VARCHAR(50),

    Age INT,

    Class VARCHAR(20)

);

 

-- Create a table with a foreign key referencing the Students table

CREATE TABLE Courses (

    CourseID INT PRIMARY KEY,

    CourseName VARCHAR(100),

    StudentID INT, -- Foreign Key referencing Students(StudentID)

    FOREIGN KEY (StudentID) REFERENCES Students(StudentID)

);

In Simple Terms

  • Imagine a table of students. Each row is a tuple representing a single student. Each column (like "StudentID", "FirstName") is an attribute. The degree of the table is the number of columns. The cardinality is the number of rows.
  • The primary key ("StudentID") is like a unique ID card for each student.
A foreign key is like a reference to another table, like linking a student's ID to their 

No comments:

Post a Comment