Relationship rules

 

Unique Primary Key:
A unique primary key is a fundamental concept in a relational database. It is a column or a combination of columns that uniquely identifies each row in a table. The primary key ensures that there are no duplicate rows in the table, and it serves as the main way to access and relate data between tables.

Key characteristics of a unique primary key:

  • Uniqueness: Each value in the primary key column(s) must be unique, meaning no two rows can have the same primary key value.

  • Non-nullability: The primary key column(s) must have non-null values. Null values are not allowed in the primary key.

Example:
Consider a table named "Employees" with columns "EmployeeID," "FirstName," and "LastName." If "EmployeeID" is defined as the primary key, it must have a unique value for each employee, and it cannot be null.

Unique Column Names:
In a relational database, each column within a table must have a unique name. This rule ensures that each column is distinguishable and that there are no ambiguities when referring to data attributes.

Example:
In a table named "Products," you cannot have two columns both named "Price." Each column should have a unique name, such as "ProductID," "ProductName," and "UnitPrice."

No Duplicate Rows:
The rule of no duplicate rows means that the combination of values in all columns of a table must be unique. In other words, two rows in the table cannot have the same values in all columns. This rule prevents redundant or repeated data in the table.

Example:
Suppose you have a table named "Orders" with columns "OrderID," "CustomerID," "ProductID," and "OrderDate." Two different orders cannot have the exact same combination of "OrderID," "CustomerID," "ProductID," and "OrderDate."

Enforcing these relationship rules is essential for maintaining data integrity and ensuring that the database remains consistent and reliable. Relational database management systems (RDBMS) typically enforce these rules automatically and reject any data modifications that violate them, ensuring that the database adheres to the specified constraints.