Grant SELECT on multiple tables
Hi,
I have created a server role in a database which needs SELECT permissions on some, but not all, tables in the database. There are almost a hundred tables that need permissions set on, so I have been trying to put together a SQL script that will do this for me. In the standard GRANT Select on... script you can name only one table to grant permissions on. Someone recommended using dynamic SQL but I have only just got to grips with the basics of SQL. This is my current attempt at using the sp_executesql stored procedure:
************************************************** ************
DECLARE @SQLString VarChar(1000)
DECLARE @TableName VarChar(100)
SET @SQLString = 'Grant Select on @TableName To "ServerRole"'
Set @Tablename='Table1'
EXEC sp_executesql @SQLString
Set @Tablename='Table2'
EXEC sp_executesql @SQLString
************************************************** ************
This generates the following error message:
"Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'."
There is probably something very obvious about my code that jumps out at an experienced (or not-so experienced) SQL person. Can anyone suggest how to improve this code, or an altogether different way of achieving the same end?
All help greatly appreciated.
Thanks,
Sharon
|