Why do you create a View in a database?

前端 未结 25 1975
一个人的身影
一个人的身影 2020-11-28 17:10

When and Why does some one decide that they need to create a View in their database? Why not just run a normal stored procedure or select?

25条回答
  •  一生所求
    2020-11-28 17:47

    There is more than one reason to do this. Sometimes makes common join queries easy as one can just query a table name instead of doing all the joins.

    Another reason is to limit the data to different users. So for instance:

    Table1: Colums - USER_ID;USERNAME;SSN

    Admin users can have privs on the actual table, but users that you don't want to have access to say the SSN, you create a view as

    CREATE VIEW USERNAMES AS SELECT user_id, username FROM Table1;
    

    Then give them privs to access the view and not the table.

提交回复
热议问题