Solved

Permissions to Databases in SSMS

Posted on 2011-09-15
11
17 Views
Last Modified: 2016-06-20
How does the user access to all the databases from Master Database they have permissions to in Sql server Management Studio?
0
Comment
Question by:catchup99
11 Comments
 
LVL 10

Expert Comment

by:pramodsk40
ID: 36546030
you can have the user as sysadmin role which will have access to all databases. Or you want access other databases from Master db ?
0
 

Author Comment

by:catchup99
ID: 36546165
I think im not clear with my question. I need a c# code to show all tables that i have permission to in Sql server Management studio
0
 
LVL 5

Expert Comment

by:25112
ID: 36546789
this is the SQL query that will tell you that.. can you plug this into C#
select name,
CanSelectAll = case when Permissions(id)&1 = 1 then 'Yes' else 'No' END ,
CanSelectAny = case when Permissions(id)&4096 = 4096 then 'Yes' else 'No' END ,
CanUpdateAll = case when Permissions(id)&2 = 2 then 'Yes' else 'No' END ,
CanUpdateAny = case when Permissions(id)&8192 = 8192 then 'Yes' else 'No' END ,
CanInsert = case when Permissions(id)&8 = 8 then 'Yes' else 'No' END ,
CanDelete = case when Permissions(id)&16 = 16 then 'Yes' else 'No' END , 
CanExecute = case when Permissions(id)&32 = 32 then 'Yes' else 'No' END
from sysobjects where type = 'U';

Open in new window

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:catchup99
ID: 36549561
The above query doesn't give which user has permissions to table. Please help me with that.
0
 
LVL 5

Accepted Solution

by:
25112 earned 125 total points
ID: 36551508
the above query will tell you what permission you have.. if you want to see for another, try this syntax..  (put/replace your userid in the first line)
execute as user = 'testIDNet';
select name,
CanSelectAll = case when Permissions(id)&1 = 1 then 'Yes' else 'No' END ,
CanSelectAny = case when Permissions(id)&4096 = 4096 then 'Yes' else 'No' END ,
CanUpdateAll = case when Permissions(id)&2 = 2 then 'Yes' else 'No' END ,
CanUpdateAny = case when Permissions(id)&8192 = 8192 then 'Yes' else 'No' END ,
CanInsert = case when Permissions(id)&8 = 8 then 'Yes' else 'No' END ,
CanDelete = case when Permissions(id)&16 = 16 then 'Yes' else 'No' END , 
CanExecute = case when Permissions(id)&32 = 32 then 'Yes' else 'No' END
from sysobjects where type = 'P';
revert;

Open in new window

0
 
LVL 5

Assisted Solution

by:25112
25112 earned 125 total points
ID: 36551559
if you want to see it for all users.. then filter it as needed..
CREATE TABLE #permissions (ObjectOwner sysname, ObjectName sysname, Grantee sysname, Grantor sysname, protecttype sysname, Privilege sysname, [column] varchar(1000))
DECLARE @DBName sysname
SET @DBName = db_name()	
INSERT #permissions EXEC ('EXEC ' + @DBName + '.dbo.sp_helprotect')

SELECT Grantee , UPPER(ProtectType) ,UPPER(Privilege) ,ObjectName
FROM #permissions, sysobjects WHERE objectname = name 

DROP TABLE #permissions

Open in new window

0
 

Author Comment

by:catchup99
ID: 36560134
Thanks for your response...Now i need to write an application in c# so that when the user login with their ID should display tables from sql that has access to and when clicked on particular table data should be displayed.
Any ideas?
0
 
LVL 5

Expert Comment

by:25112
ID: 36560722
catchup99, glad it worked for you.

This is the SQL Server Zone.. I would recommend posting the C# question in that zone for better responses. Since this is SQL zone, you are going to get help with SQL code not C# (as much)
0
 

Author Comment

by:catchup99
ID: 36560733
Thanks again for your help..
0
 
LVL 9

Expert Comment

by:Moussa Mokhtari
ID: 41661766
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Webservices in T-SQL 3 31
convert null in sql server 12 34
Whats wrong in this query - Select * from tableA,tableA 11 31
Increment column based of a FK 8 22
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question