Force INSERT only via stored procedure

后端 未结 4 1313
抹茶落季
抹茶落季 2021-01-11 18:22

Using SQL Server 2008, is there a way to allow inserts to a table only via a stored procedure, and if so how?

EDIT:
The best way to go is probab

4条回答
  •  时光说笑
    2021-01-11 19:11

    What is the motivation for the question? Is it because the stored procedure contains certain logic that you are relying on being carried out whenever data is inserted? If so you might want to use a trigger to encapsulate this logic.

    If that isn't suitable and you want to prevent even people with sysadmin permissions from inserting to the table directly, well you can't, but you can make sure that it doesn't happen accidentally by using an INSTEAD OF INSERT trigger that raises an error and rolls back unless a certain CONTEXT_INFO value is set then clears the CONTEXT_INFO (Your stored procedure could set this to the expected value)

    http://msdn.microsoft.com/en-us/library/aa214382%28SQL.80%29.aspx

提交回复
热议问题