![]() |
VOOZH | about |
The rename operator in relational databases is used to change the name of a relation (table) or its attributes (columns). It is denoted by rho (ρ). It helps in making the database schema more meaningful or clearer by providing more descriptive names. This operation doesn't change the actual data in the relation, but only the labels used to identify the relation or its attributes.
The rename operation in relational databases is considered a unary operator.
In relational databases, it's possible to rename both the relation name and its attributes.
Let's assume we have the following Employee table:
| EmpID | EmpName | EmpSalary |
|---|---|---|
| 1 | John | 50000 |
| 2 | Alice | 60000 |
| 3 | Bob | 55000 |
1. Change both the relation name and attribute names: If you want to rename both the relation (table) and the attributes (columns), the structure would look like this:
ρS(B1,B2,…,Bn)(R)
Where R is the old relation name, and S is the new name of the relation. The attributes of the relation are renamed from their original names to B1, B2, ..., Bn.
Example:ρStaff(StaffID, StaffName, Salary)(Employee): This operation indicates that the relation Employee has been renamed to Staff, and its attributes have been renamed to StaffID, StaffName, and Salary.
| StaffID | StaffName | Salary |
|---|---|---|
| 1 | John | 50000 |
| 2 | Alice | 60000 |
| 3 | Bob | 55000 |
2. Change only the relation name: In this case, you only change the relation (table) name, keeping the attribute names the same:
ρS(R)
Here, R is the old relation name, and S is the new name of the relation, while the attribute names remain unchanged.
Example: ρStaff(Employee): The relation name has changed from Employee to Staff, but the attributes (EmpID, EmpName, EmpSalary) remain unchanged.
| EmpID | EmpName | EmpSalary |
|---|---|---|
| 1 | John | 50000 |
| 2 | Alice | 60000 |
| 3 | Bob | 55000 |
3. Change only the attribute names: This option involves renaming just the attributes (columns) of the relation:
ρ(B1,B2,…,Bn)(R)
Here, the relation name R stays the same, but the column names are changed to B1, B2, ..., Bn.
Example: ρ(StaffID, StaffName, Salary)(Employee): The relation name Employee remains, but the column names are updated to StaffID, StaffName, and Salary.
| StaffID | StaffName | Salary |
|---|---|---|
| 1 | John | 50000 |
| 2 | Alice | 60000 |
| 3 | Bob | 55000 |
In relational databases, the names of the attributes in the resulting relation of SELECT and PROJECT operations are important and follow these rules:
Renaming plays a crucial role not only in making the database more readable but also when performing operations like cross-product (Cartesian product).