Skip to content
Advertisement

How to auto update column value in Child Table based on Parent Table?

My web app architecture for user access separated in two ways:- Manager Table (column: privilege) Employee Table (column: privilege, permission)

Where Manager is a Super-Admin account which will be used to subscribe our service based on package type(eg: basic, silver, gold).

For Employee, this acc will be created by Manager and share the same privilege of Manager by default(the subscribed service package). However, the Manager will need to set a permission level for each function in order for the Employee to be able to access the function in the web app.

The idea is, if session by manager acc, no permission needed. if session by employee, permission needed.

Problem: When a new row in Child table created, the default value of column ‘privilege’ should follow the same as Parent. Also, in event of Parent downgrade the privilege, the Child column value should follow as well.

Is there a way to achieve this from database perspective? I’m using postgresql. I’m aware this definitely can be achieve from backend side but with quite a lot of logic need to do for each CRUD operation.

Advertisement

Answer

You could try using triggers or stored procedures and put the logic in the database.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement