T-SQL Script for Grant(ing) permissions to all tables in a database to a user

by Hari Mukkapati 26. June 2009 04:22
set nocount on 
declare @object varchar(40) 
declare mycursor scroll cursor 
for 
   select name from sysobjects 
   where type = 'u' 
   order by name 
  
open mycursor 
fetch first from mycursor into @object 

while @@fetch_status <> -1 
begin 
  if @@fetch_status <> -2 
  begin 
     exec('grant SELECT, INSERT, UPDATE, DELETE on '+@object+' to [userid]') 
  end 
  fetch next from mycursor into @object 
end
 
close mycursor 
deallocate mycursor
 
set nocount off
Recently I was working on a database and Had to GRANT Select, Update, Delete, Insert permissions to one user on all  tables in one data base. So, Below script will do the job.
 

Tags: , , ,

Comments

10/4/2009 3:23:44 AM #

cash advance

Good post but not cool enough to rule. I usually never comment on posts, and yet I can't help leaving a comment: people never learn, they will always spam you! Amazing work.. beautiful �

cash advance United States |

10/4/2009 3:23:50 AM #

cash advance

Wow! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?

cash advance United States |

11/25/2009 11:32:29 PM #

payday loans

Nice resource. rss feed added

payday loans United States |

Comments are closed

Mukkapati.com

About the author

Hari Mukkapati

Month List

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar