We have to grant permissions to alter 6 Views to one user.
Is there any way to do it in one query, or do I have to make one query for each different view?
I have no problem doing it one by one because there's only six of them, but if I had to do it for 100 or 200, it would became impossible.
Best Answer
If you were still developing database, you could create views within a single schema, and add that user or group of users/role , permissions to alter that schema alongside permission to create view. Such as :
When you are all set and done, you can transfer those views from ViewSchema to dbo or some other more meaningful schema with command:
If views are already created, you can either add grant alter schema (name of the schema where the views reside) and add permission to user to create a view. But be aware that since you granted a user alter schema, he has all the rights on that schema, including truncating/droping tables etc..
Last option is creating a dynamic query that will grant a user/role to alter each of these views
Update
Using dynamic query would look something like this:
Note that i filtered the view names retrieval query with some silly name, you should apply your own filtering.