Why do you create a View in a database?

前端 未结 25 2032
一个人的身影
一个人的身影 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:37

    Here is how to use a View along with permissions to limit the columns a user can update in the table.

    /* This creates the view, limiting user to only 2 columns from MyTestTable */
    CREATE VIEW dbo.myTESTview 
    WITH SCHEMABINDING AS
    SELECT ID, Quantity FROM dbo.MyTestTable;
    
    /* This uses the view to execute an update on the table MyTestTable */
    UPDATE dbo.myTESTview
    SET Quantity = 7
    WHERE ID = 1
    

提交回复
热议问题