How would I go about generating a list of sql jobs and their owners? I would also like to be able to generate this list for SSIS packages also.
Thanks
try this
Jobs
select s.name,l.name
from msdb..sysjobs s
left join master.sys.syslogins l on s.owner_sid = l.sid
Packages
select s.name,l.name
from msdb..sysssispackages s
left join master.sys.syslogins l on s.ownersid = l.sid
It's better to use SUSER_SNAME() since when there is no corresponding login on the server the join to syslogins will not match
SELECT s.name ,
SUSER_SNAME(s.owner_sid) AS owner
FROM msdb..sysjobs s
ORDER BY name
A colleague told me about this stored procedure...
USE msdb
EXEC dbo.sp_help_job
If you don't have access to sysjobs table (someone elses server etc) you might be have or be allowed access to sysjobs_view
SELECT *
from msdb..sysjobs_view s
left join master.sys.syslogins l on s.owner_sid = l.sid
or
SELECT *, SUSER_SNAME(s.owner_sid) AS owner
from msdb..sysjobs_view s
There is an easy way to get Jobs' Owners info from multiple instances by PowerShell:
Run the script in your PowerShell ISE:
Loads SQL Powerhell SMO and commands:
Import-Module SQLPS -disablenamechecking
BUild list of Servers manually (this builds an array list):
$SQLServers = "SERVERNAME\INSTANCE01","SERVERNAME\INSTANCE02","SERVERNAME\INSTANCE03";
$SysAdmins = $null;
foreach($SQLSvr in $SQLServers)
{
## - Add Code block:
$MySQL = new-object Microsoft.SqlServer.Management.Smo.Server $SQLSvr;
DIR SQLSERVER:\SQL\$SQLSvr\JobServer\Jobs| FT $SQLSvr, NAME, OWNERLOGINNAME -Auto
## - End of Code block
}
Related
my MSSQL DB creates every second two SQL Server Profil - tace data file:
Screenshot
How can I stop that, because we don't want to tracing something and it files my memory?
My SELECT * FROM sys.traces is empty.
If I execute SELECT * FROM sys.server_event_sessions, the result looks like the following Screenshot:
Additionally, I execute the following command:
SELECT s.name, CAST(st.target_data AS XML).value('(/EventFileTarget/File/#name)[1]', 'NVARCHAR(100)')
FROM sys.dm_xe_sessions s
INNER JOIN sys.dm_xe_session_targets st ON s.address = st.event_session_address
WHERE target_name = 'event_file
The result looks like this:
Next, I open the system_health-file and get this displayed:
The hkenginexesession-file is empty.
Do you have enough permission to see trace list?
The visibility of the metadata in catalog views is limited to securable that a user either owns or on which the user has been granted some permission. For more information, see Metadata Visibility Configuration.
If the list is still empty with sysadmin premission then check if these files are created by Extended events:
USING SSMS:
Server > Management > Session
USING TSQL
SELECT s.name, CAST(st.target_data AS X`enter code here`ML).value('(/EventFileTarget/File/#name)[1]', 'NVARCHAR(100)')
FROM sys.dm_xe_sessions s
INNER JOIN sys.dm_xe_session_targets st ON s.address = st.event_session_address
WHERE target_name = 'event_file'
The above query return session name and filename of outputs.
I'm tasked with creating a report that will pull down the permissions from different servers and display them.
I'm having an issue with the query not picking up all of the rows in from the system view, from another server.
When I run the below query on serverA, it gives me 251 results.
SELECT COUNT(*) FROM ServerA.employee.sys.objects
When I run the same code from ServerB, I get 153 results.
I compared the two and it looks like the linked server isn't pulling type_desc of SQL_SCALAR_FUNCTION, SQL_STORED_PROCEDURE, and SYSTEM_TABLE.
Does anyone know way I can get a list of database object permissions running from a different server in SQL server?
If you are using SSRS for the report, you can setup a dynamic data source to run the same report for multiple servers/databases. I'd use a static data source at first to setup the datasets, otherwise the columns will not get created automatically.
="Data Source=" & Parameters!ServerName.Value & ";Initial Catalog=" & Parameters!DatabaseName.Value
Here is the listing of permissions on schema objects within a database.
SELECT
pr.principal_id
, pr.name
, pr.type_desc
, pr.authentication_type_desc
, pe.state_desc
, pe.permission_name
, ObjectName = s.name + '.' + o.name
FROM
sys.database_principals AS pr
INNER JOIN sys.database_permissions AS pe ON pe.grantee_principal_id = pr.principal_id
INNER JOIN sys.objects AS o ON pe.major_id = o.object_id
INNER JOIN sys.schemas AS s ON o.schema_id = s.schema_id;
Microsoft Reference
I have a list of jobs to run multiple ssis packages. I have a big list, I want to know if it is possible to run a tsql to msdb and get the information of the packages in the steps with the connection strings.
Super old thread but the below code is slightly adapted and much more useful as it shows package level details.
select
prj.name as 'ProjectName'
,pa.name as 'SSISPackageName'
,op.parameter_name as 'ParmaterName'
,op.design_default_value as 'ConnectionString'
from
catalog.object_parameters op
join catalog.projects prj
on op.project_id = prj.project_id
join [catalog].[packages] pa
on pa.project_id = prj.project_id
where op.parameter_name like '%ConnectionString%'
If your packages are stored in the SSISDB Catalog, then you would need to query on SSIDB database to get the actual connection strings. Here is what I would suggest, use the query that Rodrigo A has provided and tweak the column 'Command' further to get the packages name from it by using string functions and have the Step ID and Package Name as output. use the list of packages that you have obtained and put it in the IN clause of the following query and run it against SSISDB -
select prj.name as 'ProjectName'
,op.object_name as 'SSISPackageName'
,op.parameter_name as 'ParmaterName'
,op.design_default_value as 'ConnectionString'
from catalog.object_parameters op
join catalog.projects prj
on op.project_id = prj.project_id
where op.parameter_name like '%ConnectionString%'
and op.object_name in (
--put the package name list here
);
You can then join on the result sets, to get the step Id, PackageName and the connection strings in that package.
Run this query over the server you want to check:
SELECT [sJSTP].[step_id], Name, sJSTP.Command FROM [msdb].[dbo].[sysjobs] [sJOB]
LEFT JOIN [msdb].[dbo].[sysjobsteps] AS [sJSTP]
ON [sJOB].[job_id] = [sJSTP].[job_id]
AND [sJOB].[start_step_id] = [sJSTP].[step_id]
ORDER BY Name, step_id
Cheers!
Hopefully a simple question here:
How do I get the permissions for an SQL Server table_type?
I know how to grant them, ie like:
GRANT [permission] ON TYPE::[schema_name].[type_name] TO [user]
As per http://technet.microsoft.com/en-us/library/ms174346.aspx.
What I want to know however, is how to find out what permissions users already have on a particular table_type. I've tried looking through tables like INFORMATION_SCHEMA.TABLE_PRIVILEGES, sys.database_permissions and sys.syspermissions, but I haven't had any luck.
My guess is I'm either missing something obvious or that the privileges for table_types are stored elsewhere.
You'll want to use the user_type_id from sys.table_types to join to sys.database_permissions:
SELECT prmssn.*
FROM sys.table_types AS tt INNER JOIN sys.database_permissions AS prmssn ON prmssn.major_id=tt.user_type_id
WHERE tt.name='<Table-Type Name>'
AND SCHEMA_NAME(tt.schema_id)='<SchemaName>')
Try this:
SELECT *
FROM sys.database_permissions a
JOIN sys.database_principals b on a.grantee_principal_id = b.principal_id
where major_id=object_id('dbo.TableNameHere')
How can i check with SQL query whether Database backup JOB is created or not ?
Thank You
This query will return all jobs that have the command BACKUP DATABASE in them:
SELECT SV.name,
SV.description,
S.step_id
FROM msdb.dbo.sysjobs_view SV
INNER JOIN msdb.dbo.sysjobsteps S ON SV.job_id = S.job_id
WHERE s.command LIKE '%BACKUP DATABASE%'
If you setup the job categories properly to have a category called 'Database Backup' the following would also work:
SELECT SV.name,
SV.description
FROM msdb.dbo.sysjobs_view SV
INNER JOIN msdb.dbo.syscategories SC ON SV.category_id = SC.category_id
WHERE SC.Name = 'Database Backup'