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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -