The relational model is a type of model, which represents how the data are stored in a relational database.
In a relational database, data is stored in the form of tables (relations). Tables are a combination of rows and columns. In a table, columns represent an attribute of an entity, and rows represent records.
The relational model is proposed by E.F. Codd in 1969.
In the whole world, the relational model demand of the relational model is very high. Because this is not a type of complex model as before and programmers can easily work on it. It also fulfills all the needs of data processing and storage.
For example, a table named STUDENT is given:
ID | NAME | COURSE | ADDRESS |
1. | ABHISHEK | B.TECH | BIHAR |
2. | NISHANT | B.TECH | BIHAR |
3. | PRAKASH | B.PHARMA | UP |
4. | ALOK | MBBS |
Important terms of relational model
1. Attribute
An attribute is the property of a table which defines the relation or table.
For example: in the above table STUDENT, ID, NAME, COURSE, AND ADDRESS are the attributes of the table.
2. Tuple
Each row of a table is known as a tuple. In the above table STUDENT, there are four tuples. One tuple is shown below.
2. | NISHANT | B.TECH | BIHAR |
3. Degree
Total no of attributes in a table is known as the degree of that table. The degree of above STUDENT is 4. Because there are four attributes present in the table.
4. Relational schema
It represents attributes with the name of their table.
For example, STUDENT (ID, NAME, COURSE, ADDRESS) is a relation schema for the table STUDENT.
5. Cardinality
Total no of tuples presents in the table is the cardinality of that table. For example, the cardinality of the above table STUDENT is 4. Because total tuple or row in this table is 4.
6. Null values
The value which is not available in the table is known as a NULL value. For example: for id 4 in the above STUDENT table address value is not available. So here address value is NULL.
Relational model Constraints
There are some conditions are always present for each relation. These conditions are called relational integrity constraints.
Basically, there are three types of constraints of the relational model:
- Key constraints
- Domain constraints
- Referral integrity constraints
1. Key Constraints
Key constraints are used to identify each record in a table uniquely. The most common types are:
- Primary Key Constraint: Ensures that a column or a group of columns have unique values across the table. No part of a primary key can be null. This uniqueness ensures that every record can be uniquely identified.
- Foreign Key Constraint: Used to establish a link between two tables. It relates the foreign key in one table to the primary key in another, ensuring the consistency of data across tables.
Key constraints maintain the uniqueness and integrity of data within and across tables, helping enforce relationships between tables.
2. Domain Constraints
Domain constraints specify the permissible values for a given attribute. They define the data type (such as integer, decimal, character, date), range of values, default value, and whether the value can be null. For instance, a domain constraint can limit an “age” field to only integer values between 1 and 100, ensuring that only valid ages are entered into the database.
These constraints are crucial for data accuracy and consistency, ensuring that attributes in a database table adhere to specified rules, such as allowable values and data types.
3. Referential Integrity Constraints
Referential integrity constraints ensure that relationships between tables remain consistent. Specifically, they make sure that a foreign key field in one table correctly refers to a primary key field in another table. This constraint is key to maintaining the accuracy and consistency of data across related tables.
For example, in a database with “students” and “enrollments” tables, a referential integrity constraint would ensure that every record in the “enrollments” table points to an existing record in the “students” table. This prevents situations where an enrollment could exist without a corresponding student, thereby maintaining the logical integrity of the database.
These three types of constraints are fundamental to relational database design, each serving to ensure the quality, integrity, and reliability of the data within the database system.