-2

I'm using SQL Server, and I'm connecting as admin via sqlcmd. I want to know if I'm actually connected as admin. Is there any command or query that only admins can do?

Thanks, Gal

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gal Malka
  • 307
  • 3
  • 12

2 Answers2

0

This query should give you a list of the members of the sysadmin role. If you add to the where clause to filter for only the current user, you should get what you need. (It was copied from this SO question.)

SELECT p.name AS [Name] ,r.type_desc,r.is_disabled,r.create_date , r.modify_date,r.default_database_name
FROM
sys.server_principals r
INNER JOIN sys.server_role_members m ON r.principal_id = m.role_principal_id
INNER JOIN sys.server_principals p ON
p.principal_id = m.member_principal_id
WHERE r.type = 'R' and r.name = N'sysadmin'
Community
  • 1
  • 1
DeadZone
  • 1,633
  • 1
  • 17
  • 32
0

This script tell you - You are connected as DAC or not

select 'Yes you have connected as "DAC"' [Who you are] from sys.dm_exec_sessions s join sys.endpoints  e
on (s.endpoint_id = e.endpoint_id) 
where e.name ='Dedicated Admin Connection'
and s.session_id = @@spid