Solved

Permissions to Databases in SSMS

Posted on 2011-09-15
11
13 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now