I have a script which creates a database, stored procs, views, tables, udf. I want to include a script to create a user ‘user_1’ and give execute permission on the database.
I tried following to create grant exec command for all stored procs
declare @permission varchar(max)
select @permission = COALESCE(
@permission + '; ' + 'Grant Execute on ' + name + ' user_1',
'Grant Execute on ' + name + ' user_1')
from sysobjects where xtype in ('P')
exec (@permission)
But exec (@permission) does not work. It gives
incorrect syntax near ‘;’.
How can I solve this?
Create Login: creates the server level login. Then…
Create User: lets the Login account attach to your database. Then…
Grant Execute To: grants execute rights to ALL of the sp’s and functions in your db. Use “Grant Execute ON abc TO xyz” if you only want to grant rights to specific sps.