I am looking for a query to run on SQL server to identify who can change DB objects structure (DLL) within a SQL server. Please help. Thank you.
You can look in the Default Trace:
SELECT TE.name AS EventName ,
T.DatabaseName ,
t.ObjectName,
t.NTDomainName ,
t.ApplicationName ,
t.LoginName ,
t.StartTime
FROM sys.traces tr
cross apply sys.fn_trace_gettable(CONVERT(VARCHAR(150),
( SELECT f.[value] FROM sys.fn_trace_getinfo(tr.id) f WHERE f.property = 2 )), DEFAULT) T
JOIN sys.trace_events TE ON T.EventClass = TE.trace_event_id
WHERE
tr.is_default = 1
and name like 'Object:%'
ORDER BY t.StartTime ;
Thanks for efforts. I found the following site which gives you multiple queries determining effective database engine permissions.
https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/determining-effective-database-engine-permissions?view=sql-server-2017
Related
Would you know what could be the code error on query with my tables and server database connection, I normally list my query in the following format and today it provides me with the same continued error and only this query is displaying this type of error. My tables are referencing the correct database due to the reason that this is the only database that hods these tables. My query code listed below, maybe its missing something.
SELECT Distinct
'CA' AS 'Server'
, DATENAME(month, res.Move_in_Date) [MonthName]
, DATEPART(day, res.Move_in_Date) [Day]
, DATENAME(WEEKDAY, res.Move_in_Date) [Weekday]
, res.Move_in_Date
, res.Move_out_Date
, ge.Entity_Number
, bld.Building_Name
, addr.Address2
, addr.City
, addr.State
, addr.Zip_Code
, bld.Building_ID
, unts.Unit_Number
, res.First_Name
, res.Last_Name
, ge.Active AS GL_Entities_Active
, bld.Building_Active
FROM
acct.cam_ca.dbo.residents AS res
INNER JOIN
acct.cam_ca.dbo.units AS unts
ON res.Unit_ID = unts.Unit_ID
INNER JOIN
acct.cam_ca.dbo.addresses AS addr
INNER JOIN
acct.cam_ca.dbo.gl_entities AS ge
ON addr.Address_ID = ge.Address_ID
INNER JOIN
acct.cam_ca.dbo.buildings AS bld
ON ge.GL_Entity_ID = bld.GL_Entity_ID ON unts.Building_ID = bld.Building_ID
WHERE
ge.Active = 1
AND ge.Entity_Number = 1
AND bld.Building_Active = 1
AND res.Move_in_Date BETWEEN '20200101 00:00:00.000 AM' AND '20200707 11:59:59 PM'
ORDER BY
ent.Entity_Number
, res.Move_in_Date
As can be read from the error message the server mentioned in the query is not available in metadata view sys.servers.There are two possibilities,
The server "acct" is not available.
The server "acct" is defined but could have a different name
defined.
Troubleshoot by running queries Run the query below to list all available servers ,
select name,data_source from sys.servers
Try to identify the name corresponding to the data_source and use that name instead of acct for the server in your query.
If you are unable to identify a relevant entry, contact DBA to provide the details of the server.
Your query is trying to access tables on a different server, accessed through a linked server called acct. For example, in your code you have acct.cam_ca.dbo.residents. Here:
residents is the table name
dbo is the schema name
cam_ca is the database name
acct is the linked server name
Either the linked server used to exist but has been deleted by a DBA, or you are running your query on a different server from the one where it works and this new server does not have the acct linked server set up, or you have changed the query.
I'm currently working in a Netezza environment on Aginity Workbench and I was planning on using some of the columns from the Management View _V_QRYSTAT to populate a graph in MicroStrategy.
Unfortunately, I cannot get MicroStrategy to recognize any of the columns in _V_QRYSTAT. I don't think that it can read columns from views, and I figured that the best way around this would be to find out which table the _V_QRYSTAT view is getting its data from, but I can't figure out a way to find the source table of a view in Netezza. Does anyone know a method that can be used in Netezza on Aginity Workbench for locating the source table of a view (specifically _V_QRYSTAT)?
I'm very new to SQL, Netezza and MicroStrategy, so I apologize if I am being unclear. Let me know if further elaboration is needed.
I'm pretty sure that MicroStrategy will recognize and work with views, but to answer your question directly, you can see the view definition by querying the _V_VIEW system view.
select definition from _v_view where viewname = '_V_QRYSTAT';
DEFINITION
---------
SELECT
QS.QS_SESSIONID,
QS.QS_PLANID ,
QS.QS_CLIENTID ,
CASE
WHEN ((VU.OBJID NOTNULL
)
OR ("CURRENT_USEROID"() = 4900
)
)
THEN QS.QS_CLIIPADDR
ELSE "NAME"(NULL::"VARCHAR")
END AS QS_CLIIPADDR,
CASE
WHEN ((VU.OBJID NOTNULL
)
OR ("CURRENT_USEROID"() = 4900
)
)
THEN QS.QS_SQL
ELSE TEXT(NULL::"VARCHAR")
END AS QS_SQL ,
QS.QS_STATE ,
QS.QS_TSUBMIT ,
QS.QS_TSTART ,
QS.QS_PRIORITY,
QS.QS_PRITXT ,
QS.QS_ESTCOST ,
QS.QS_ESTDISK ,
QS.QS_ESTMEM ,
QS.QS_SNIPPETS,
QS.QS_CURSNIPT,
QS.QS_RESROWS ,
QS.QS_RESBYTES
FROM
((DEFINITION_SCHEMA."_T_QRYSTAT" QS
LEFT JOIN DEFINITION_SCHEMA."_T_SESSCTX" SS ON (
(QS.QS_SESSIONID = SS.SESSION_ID
)
))
LEFT JOIN DEFINITION_SCHEMA."_V_USER" VU ON (
(SS.SESSION_USERNAME = VU.USERNAME
)
));
(1 row)
This will almost certainly take you a couple of recursions down, as the view you are interested in is based on either views as well as tables.
I try to resolve my problem since two days but I my code fails... Do you know how I can conert my sql query in doctrine ?
Sql query (the query work fine in phpmyadmin) :
SELECT distinct ms.ytId, ms.title FROM(
SELECT l.log_yt_id AS ytId, d.download_title AS title
FROM t_log l LEFT JOIN t_download d ON d.download_yt_id = l.log_yt_id WHERE l.log_creator = 'n' ORDER BY l.log_id DESC LIMIT 100
) ms
Thanks you all for your help !!
Best regards,
You can use doctrine dql.
First:
Check this page:
http://docs.doctrine-project.org/en/2.1/reference/dql-doctrine-query-language.html
Then remember:
If you want to use mysql functions like "RAND" etc. you have to define them in your config file after install a doctrine extensions bundle.
This question already has answers here:
List the queries running on SQL Server
(17 answers)
Closed 7 years ago.
Is there a program or a sql query that I can find which SQL queries are being run on an SQL Server 2012? I think there was a tool in earlier version of SQL Server where the actual query content gets displayed or the stored procedure name?
I use the below query
SELECT SPID = er.session_id
,STATUS = ses.STATUS
,[Login] = ses.login_name
,Host = ses.host_name
,BlkBy = er.blocking_session_id
,DBName = DB_Name(er.database_id)
,CommandType = er.command
,ObjectName = OBJECT_NAME(st.objectid)
,CPUTime = er.cpu_time
,StartTime = er.start_time
,TimeElapsed = CAST(GETDATE() - er.start_time AS TIME)
,SQLStatement = st.text
FROM sys.dm_exec_requests er
OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) st
LEFT JOIN sys.dm_exec_sessions ses
ON ses.session_id = er.session_id
LEFT JOIN sys.dm_exec_connections con
ON con.session_id = ses.session_id
WHERE st.text IS NOT NULL
Depending on your privileges, this query might work:
SELECT sqltext.TEXT,
req.session_id,
req.status,
req.command,
req.cpu_time,
req.total_elapsed_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
Ref: http://blog.sqlauthority.com/2009/01/07/sql-server-find-currently-running-query-t-sql
There's this, from SQL Server DMV's In Action book:
The output shows the spid (process identifier), the ecid (this is similar to a thread within the same spid and is useful for identifying queries running in parallel), the user running the SQL, the status (whether the SQL is running or waiting), the wait status (why it’s waiting), the hostname, the domain name, and the start time (useful for determining how long the batch has been running).
The nice part is the query and parent query. That shows, for example, a stored proc as the parent and the query within the stored proc that is running. It has been very handy for me. I hope this helps someone else.
USE master
GO
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT
er.session_Id AS [Spid]
, sp.ecid
, er.start_time
, DATEDIFF(SS,er.start_time,GETDATE()) as [Age Seconds]
, sp.nt_username
, er.status
, er.wait_type
, SUBSTRING (qt.text, (er.statement_start_offset/2) + 1,
((CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE er.statement_end_offset
END - er.statement_start_offset)/2) + 1) AS [Individual Query]
, qt.text AS [Parent Query]
, sp.program_name
, sp.Hostname
, sp.nt_domain
FROM sys.dm_exec_requests er
INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle)as qt
WHERE session_Id > 50
AND session_Id NOT IN (##SPID)
ORDER BY session_Id, ecid
here is what you need to install the SQL profiler http://msdn.microsoft.com/en-us/library/bb500441.aspx. However, i would suggest you to read through this one http://blog.sqlauthority.com/2009/08/03/sql-server-introduction-to-sql-server-2008-profiler-2/ if you are looking to do it on your Production Environment.
There is another better way to look at the queries watch this one and see if it helps
http://www.youtube.com/watch?v=vvziPI5OQyE
The tool is called the SQL Server Profiler, it's still part of the standard toolset.
You are talking about SQL Profiler.
i know sql server and not oracle, so i will speak in sql server language to describe what i need from oracle.
i have a oracle query i am developing that needs to select the following fields detailed below. i found all but two of them in the BUG table. the other two are in other tables that i am not clear on how to get into my oracle SQL.
also i want to convert the field names defined in Oracle to field names that are more meaningful to me and indecently the dame as the field names in my sql table. (this is part of an oracle extract/ sql2005 insert job) this may need to be oricalafied as well cause im writing it the sql way and just expecting it to work... let me know.
my sql so far- i added '' as placeholders for the 2 fields i need to join to:
BG_SUBJECT field is part of the ALL_LISTS Table, where AL_ITEM_ID is the primary key.
DetectedInRelease is the REL_NAME field in the RELEASES table where REL_ID is the primary key.
SELECT
bg_user_56 AS Project,
bg_user_60 AS SubSystem,
BG_USER_81 AS AssignedToUserName,
bg_responsible AS AssignedTo,
bg_status AS Status,
BG_USER_15 AS BusinessFunction,
bg_detection_date AS DetectedOnDate,
BG_SEVERITY AS BusinessSeverity,
bg_user_36 AS TestingSeverity,
bg_bug_id AS DefectID,
Bg_User_09 AS EstFixedDate,
bg_user_25 AS EstReadyForRetest,
BG_DESCIPTION AS description,
BG_USER_03 AS DetectedInDeploymentEvent,
'' AS DetectedInRelease,--- ??? not in bug table !!!!
BG_USER_47 AS FunctionalAreaWorkstream,
BG_USER_19 AS PlannedFixInDeploymentEvent,
BG_USER_55 AS PlannedFixInRelease,
BG_USER_57 AS PTMTestManager,
Bg_User_58 AS RemediatingCTOName,
'' AS Subject,--- ??? not in bug table !!!
bg_summary AS Summary,
bg_user_80 AS MLTestEnvironment,
GETDATE() AS LoadDateTime,
bg_user_12 AS Deferred
FROM tascs_ml_bac_transition_db.BUG
the query syntax is effectively the same, GETDate will need to be SYSDATE however, included as a sample inner join
SELECT
BUG.bg_user_56 AS Project ,
BUG.bg_user_60 AS SubSystem ,
BUG.BG_USER_81 AS AssignedToUserName ,
BUG.bg_responsible AS AssignedTo ,
BUG.bg_status AS Status ,
BUG.BG_USER_15 AS BusinessFunction ,
BUG.bg_detection_date AS DetectedOnDate ,
BUG.BG_SEVERITY AS BusinessSeverity ,
BUG.bg_user_36 AS TestingSeverity ,
BUG.bg_bug_id AS DefectID ,
BUG.Bg_User_09 AS EstFixedDate ,
BUG.bg_user_25 AS EstReadyForRetest ,
BUG.BG_DESCIPTION AS description ,
BUG.BG_USER_03 AS DetectedInDeploymentEvent ,
REL.REL_NAME AS DetectedInRelease , --- ??? not in bug table !!!!
BUG.BG_USER_47 AS FunctionalAreaWorkstream ,
BUG.BG_USER_19 AS PlannedFixInDeploymentEvent,
BUG.BG_USER_55 AS PlannedFixInRelease ,
BUG.BG_USER_57 AS PTMTestManager ,
BUG.Bg_User_58 AS RemediatingCTOName ,
al.BG_SUBJECT AS Subject , --- ??? not in bug table !!!
BUG.bg_summary AS Summary ,
BUG.bg_user_80 AS MLTestEnvironment ,
sysdate AS LoadDateTime , --changed to sysdate
BUG.bg_user_12 AS Deferred
FROM
tascs_ml_bac_transition_db.BUG BUG
INNER JOIN
ALL_LISTS al
ON BUG.AL_ITEM_ID = al.AL_ITEM_ID --THIS ASSUMES AL_ITEM_ID IS COMMON FIELD
INNER JOIN
RELEASES REL
ON BUG.REL_ID = REL.REL_ID --THIS ASSUMES REL_ID IS COMMON FIELD
I'm going to take a stab at this:
SELECT
bg_user_56 AS Project,
bg_user_60 AS SubSystem,
BG_USER_81 AS AssignedToUserName,
bg_responsible AS AssignedTo,
bg_status AS Status,
BG_USER_15 AS BusinessFunction,
bg_detection_date AS DetectedOnDate,
BG_SEVERITY AS BusinessSeverity,
bg_user_36 AS TestingSeverity,
bg_bug_id AS DefectID,
Bg_User_09 AS EstFixedDate,
bg_user_25 AS EstReadyForRetest,
BG_DESCIPTION AS description,
BG_USER_03 AS DetectedInDeploymentEvent,
rel.BG_DetectedInRelease AS DetectedInRelease,--- ??? not in bug table !!!!
BG_USER_47 AS FunctionalAreaWorkstream,
BG_USER_19 AS PlannedFixInDeploymentEvent,
BG_USER_55 AS PlannedFixInRelease,
BG_USER_57 AS PTMTestManager,
Bg_User_58 AS RemediatingCTOName,
al.BG_SUBJECT AS Subject,--- ??? not in bug table !!!
bg_summary AS Summary,
bg_user_80 AS MLTestEnvironment,
GETDATE() AS LoadDateTime,
bg_user_12 AS Deferred
FROM tascs_ml_bac_transition_db.BUG B, ALL_LISTS al, releases rel
WHERE al.al_item_id = b.al_item_id and rel.rel_id = b.rel_id;
It's hard to guess if this will work since I don't have a complete DDL of these tables, but this is my best guess based on what you've given. I assumed that BUG had fields with the same names as the ones you need to join on. This might not be valid, feel free to clarify.
You could also use INNER JOIN ON syntax if you prefer it.