Search code examples
sqldatabaseoracle-databaserdbms

How to make a unified Table for more than entries but retrieve different columns name for each entity in SQL?


I have different entities but, ironically, in same time they are very similar, and I wonder if I can save them in one united table.

I need four tables for Departments, Committees, Groups, and Bands in which columns for department table should be (Name,Code), Committees should be (Title,ID) , and Group (Description,Num) , and Bands (symbol,Figures)

I thought to make a united table in which there is another field (Column) to hold the row-type, and make columns name (FLD01,FLD02,FLD03,FLD04, etc). and make anther table to hold mapping

Departments FLD01   Name
Departments FLD02   Code
Committees  FLD01   Title
Committees  FLD02   ID
Groups      FLD01   Description
Groups      FLD02   Num
Bands       FLD01   symbol
Bands       FLD02   Figures

I retrieve data with SQL and wonder if there is a way to join that united table to this table so I can automatically get columns names instead of FLD01, FLD02..etc. be informed that I will retrieve only on type (department, band, ...) at a time..


Solution

  • In theory, sure, you could write a dynamic pipelined table function and always retrieve the data via this pipelined table function.

    Practically, if the similarity is that all these entities have the same number and type of columns but the columns have different names, it seems very unlikely that it makes sense from a data model standpoint to combine them.