0

Sorry If my question is too dumb. Recently I have learned about database view. As far as I understand view is mainly used to encapsulate complex query, Handle security related issues like permission and simplify supporting lagacy code.

So I have a single table and different types of user can only work on different column of the table. Is it ok to use view to manage permission in this scenerio ?

4
  • 1
    Are you asking if you can use a View to expose different columns to different users? Which database system are you using?
    – J.D.
    Sep 3, 2023 at 23:09
  • Yes, I am using PostgreSQL
    – pi3o1416
    Sep 4, 2023 at 4:20
  • Yes, views are commonly used for this scenario. You create views that only show certain columns (or certain rows) and grant access to those views to your users. Do not grant access on the base table. That way, you know that you users can only see the data they are allowed to see. Sep 4, 2023 at 8:29
  • Thanks that helps a lot
    – pi3o1416
    Sep 4, 2023 at 8:48

1 Answer 1

0

... encapsulate complex query ...

Yes, Views can do that, calculating "dynamic" values on the fly (like age from a stored date_of_birth or an Order total from the individual Order Lines).

... Handle security related issues like permission ...

Not so sure about this one.
Views can be used to restrict access to tables - only giving "read" access through a View and not giving permissions on the underlying table(s).
Views can also get you things like Row-based-Security, where a User can only access their own data in a table based on some column.

I would hesitate to put "Views" and "Permissions" together directly as concepts
Which User or Group has access to which database object(s) - i.e. Database Permissions - remains a separate thing.

... simplify supporting legacy code.

Maybe, maybe not.
It depends entirely on the legacy application.
In some cases, trying to "inject" Views into the code can make things a whole lot more difficult.

I have a single table and different types of user can only work on different column of the table. Is it ok to use view to manage permission in this scenario ?

Absolutely, yes.
Each community of Users would be given permission on a View that meets their needs and wouldn't even know that the others exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.