sql - Can I give a Stored Procedure permission to SET IDENTITY_INSERT? -
i have stored procedure give permission insert identities while not giving restricted user calling alter table privileges. possible?
here's stored procedure:
create procedure [dbo].[addinternalqu] ( @id [int], @qu [nvarchar](500), @pg [nvarchar](50), @isactive [bit], @isdoc [bit], @allowna [bit], @textbox [bit], @redf [bit], @qord [int], @shqu [nvarchar](50), @restrict [bit], @scanwizard [bit] ) begin set identity_insert [questions] on; insert [questions] (qu_id, question, shortqu, redflag, page, active, is_doc_qu, allowna, textbox, qu_order, scanwizard, restricted) values(@id, @qu, @shqu, @redf, @pg, @isactive, @isdoc, @allowna, @textbox, @qord, @scanwizard, @restrict); set identity_insert [questions] off; end grant exec on addinternalqu mystandardrole;
as stands user add mystandardrole
role has rights execute stored procedure fails trying set identity insert insufficient privileges.
"with execute owner" should trick.
create procedure [dbo].[addinternalqu] ( @id [int], @qu [nvarchar](500), @pg [nvarchar](50), @isactive [bit], @isdoc [bit], @allowna [bit], @textbox [bit], @redf [bit], @qord [int], @shqu [nvarchar](50), @restrict [bit], @scanwizard [bit] ) execute owner begin set identity_insert [questions] on; insert [questions] (qu_id, question, shortqu, redflag, page, active, is_doc_qu, allowna, textbox, qu_order, scanwizard, restricted) values(@id, @qu, @shqu, @redf, @pg, @isactive, @isdoc, @allowna, @textbox, @qord, @scanwizard, @restrict); set identity_insert [questions] off; end grant exec on addinternalqu mystandardrole;
Comments
Post a Comment