• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 69
  • Last Modified:

Need to iterate through table names and run a grant statement against it.

Does anyone have some code they can share with me. I need to grab table names in a database and grant permissions on the tables. I think this can be done with a Cursor, but I don't know how to do it, and am up against a deadline. If someone can help I would really appreciate it.
1 Solution
Pawan KumarDatabase ExpertCommented:
You need to do like below -

declare curs cursor
SELECT tableName from yourtable /* This you can replace with your query of fetching tableNames from the query */

OPEN curs 


fetch curs into @TableName

while (@@sqlstatus != 2)
--Write grant permissions here...


Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now