Creating readonly views in Sql Server

后端 未结 3 992
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 18:17

According to MSDN, views composed of simple selects automatically allow you to use insert/update/delete statements on the table. Is there a way to prevent this - to tell Sql

3条回答
  •  情歌与酒
    2020-12-03 18:37

    The best way would be to remove UPDATE/DELETE/INSERT permissions on the View.

    Apart from that you could create an INSTEAD OF trigger on the view that simply does nothing to have the updates silently fail or there are quite a few constructs that make views non updatable. So you can pick one that doesn't change semantics or efficiency and then violate it.

    Edit: The below seems to fit the bill.

    CREATE VIEW Bar
    AS
    SELECT TOP 100 PERCENT x
    FROM foo
    WITH CHECK OPTION
    

提交回复
热议问题