Sorry for lame question but I am literally starting with DNN.
When you are in admin/design mode you can list all modules used, and when you click on module at the end you will see the list of controls used in this module with info about filename of the source.
The problem I have is in reverse -- I already know the filename with source, I would like to list all modules which use this control. How to do it?
If you want to find module definitions with a control, use a query like
SELECT *
FROM
ModuleDefinitions md
INNER JOIN ModuleControls mc on (mc.ModuleDefID = md.ModuleDefID)
WHERE ControlSrc like '%filename%'
If you want to find the modules that are actually used, you'll have to join with Tabs, TabModules and Modules tables. For example:
SELECT
t.PortalID
,t.TabID
,t.TabName
,m.ModuleID
,md.FriendlyName
,mc.ControlSrc
FROM
Tabs t
INNER JOIN TabModules tm ON t.TabID = tm.TabID
INNER JOIN Modules m on tm.ModuleID = m.ModuleID
INNER JOIN ModuleDefinitions md ON m.ModuleDefID = md.ModuleDefID
INNER JOIN ModuleControls mc on mc.ModuleDefID = md.ModuleDefID
WHERE ControlSrc like '%filename%'
Related
I'm trying to update a query for a client to add more functionality on a MS-SQL Server 2014 database. The query was written by someone else, and is currently working.
The FROM part of the query contains the following:
FROM Project Phs
LEFT JOIN (SELECT * FROM Stage WHERE Status >=5 ) SUB
ON pmsProject = phs.prjPhase
LEFT JOIN InvoiceGroup ON phs.prjInvoiceGroup = igKey
LEFT JOIN Vec ON vecKey = igClient
LEFT JOIN Project Prj ON Prj.prjkey = Phs.prjproject
LEFT JOIN Contact ON prj.prjClientContact1 = cntkey
LEFT JOIN Project L2 ON L2.prjkey = phs.prjPhaseLevel2
What does SUB on line 2 do here?
I can't find SUB in the JOIN documentation, SUB is not a reserved word in T-SQL, and SUB does not appear anywhere else in the (300 line) query. Thanks.
Sub is nothing more than a table alias from which the columns from the stage table can be referenced.
The join could be written as sub.pmsProject=phs.prjphase.
It's similar to phs for project and prj for project.
All fields from the stage table can be refereed to as sub.fieldname. This is necessary when tables have fields with the same name so the engine knows specifically what table you want to access data from.
Aliases not only make it easier to code, it makes the code easier to read instead of having long drawn out table names.
This is simply an alias for the (SELECT * FROM Stage WHERE Status >=5 ) subquery so that it can be referenced later. I do not see it referenced anywhere else in the query you have provided, but you may have trimmed off a portion that contains it, or it may have been removed previously.
I need and update on Table exp_pedcom on cases where a field of another table are null ( EXP_Procimp), but these two table do not have a direct relation to each other, so I actully need to "route" it though two other tables in order to relate them. The "routed! relation works, it returns as expected, but the update doesn't. I've tryed both as a direct inner join using from and as a subquery ( which is actually easier to demonstrate, so That's what goes here.
UPDATE EXP_PEDCOM
SET STATUS_ATENDIMENTO=0
WHERE EXP_PROCIMP.DAT_RECEBIMENTO IS NOT NULL IN (SELECT EXP_PROCIMP.DAT_RECEBIMENTO
FROM
EXP_PEDCOM INNER JOIN
EXP_INVOICE_IT ON EXP_PEDCOM.NUM_PEDCOM = EXP_INVOICE_IT.NUM_PEDCOM INNER JOIN
EXP_INVOICE ON EXP_INVOICE_IT.COD_DOCUMENTO = EXP_INVOICE.COD_DOCUMENTO INNER JOIN
EXP_PROCIMP ON EXP_INVOICE.NUM_PROCIMP = EXP_PROCIMP.NUM_PROCIMP)
Any tips?
The following shows how to use it using the UPDATE... FROM... syntax. (I messed with formatting and aliases while working out what the query actually did.)
UPDATE EXP_PEDCOM
set STATUS_ATENDIMENTO = 0
from EXP_PEDCOM
inner join EXP_INVOICE_IT it
on EXP_PEDCOM.NUM_PEDCOM = it.NUM_PEDCOM
inner join EXP_INVOICE iv
on it.COD_DOCUMENTO = iv.COD_DOCUMENTO
inner join EXP_PROCIMP pr
on iv.NUM_PROCIMP = pr.NUM_PROCIMP
where pr.DAT_RECEBIMENTO is not null
This will work [caveat: I could not run and so debug possible syntax glitches], but it's hard to explain why/how this works. It's also a tad unconventional; hopefully you'll get other posts that show the "proper" way to run such queries.
I would like to see for each portal how many times a particular module was viewed, that is number
of views for a module based on role.
Can we generate this using SQL Query.
Regards,
To find usage first you must have site logs on. Second there is no exact logging per-module. Because one Tab may have more than one module on it. However we can imagine if page is viewed - all modules on that page are viewed. I think following query is going to give you count by module
SELECT R.PortalID,
TM.ModuleID,
R.RoleName,
COUNT(1) TotalViews
FROM Roles R WITH ( NOLOCK )
INNER JOIN dbo.UserRoles UR WITH ( NOLOCK ) ON R.RoleID = UR.RoleID
INNER JOIN dbo.SiteLog sl WITH ( NOLOCK ) ON sl.UserId = ur.UserID
INNER JOIN dbo.TabModules tm WITH ( NOLOCK ) ON tm.TabID = sl.TabId
GROUP BY R.PortalID,
TM.ModuleID,
R.RoleName
However result will not be that useful because one user may belongs to more than one role. Second I have ignored join with ModulePermissions because most modules do use inherit view permissions.
Is there any way to know if a particular table is being referenced by any Views or not.I used the below code which gives only SP's and function names:
select * from sys.objects p inner join sys.sql_modules m
on p.object_id = m.object_id
where m.definition like '%abc%'
Please help!!!
select *
from INFORMATION_SCHEMA.VIEWS
where VIEW_DEFINITION like '%abc%'
First, your query gives views in the result set (I tried it on AdentureWorks2012 -> Production.Product table):
If you're using SQL Server 2008 or above, you can use the sys.sql_expression_dependencies catalog view. For example:
SELECT
referencing_object_name = o.name,
referencing_object_type_desc = o.type_desc,
referenced_object_name = referenced_entity_name,
referenced_object_type_desc = o1.type_desc
FROM sys.sql_expression_dependencies sed
INNER JOIN sys.objects o
ON sed.referencing_id = o.[object_id]
LEFT OUTER JOIN sys.objects o1
ON sed.referenced_id = o1.[object_id]
WHERE referenced_entity_name = 'YourTable'
It will give you nice look on each by-name dependency on a user-defined entity
For column level dependencies you can use the sys.dm_sql_referenced_entities function
Hope this helps
If you need to find database objects (e.g. tables, columns, triggers) by name - have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).
It's a great must-have tool for any DBA or database developer - did I already mention it's absolutely FREE to use for any kind of use??
If that doesn't fit your bill - you could also check out the sysdepends catalog view in SQL Server - it lists what objects depend on what (see details in the MSDN docs).
To find out what objects depend on a given table, you could use something like:
SELECT
id,
OBJECT_NAME(ID)
FROM sys.sysdepends
WHERE depid = OBJECT_ID('YourTable')
That should give you a list of all objects depending on that table (or view or whatever you're checking)
When I create a view in SQL Server 2005 and someone later opens it in the GUI modify mode it sometimes completely rearranges my joins. Often to the point it's virtually no longer readable. If I look at it in the GUI it's changed as well from what I originally wrote. Sometimes the join lines no longer even point to a field and the join symbol has "fx". I assume it has "optimized" it for me. Is there a way to prevent this from happening? And what does "fx" mean?
Originally it was something like this:
FROM dbo.Stop
LEFT OUTER JOIN dbo.StopType ON dbo.Stop.StopTypeID = dbo.StopType.StopTypeID
LEFT OUTER JOIN dbo.CityState ON dbo.Stop.City = dbo.CityState.City AND dbo.Stop.State = dbo.CityState.State
LEFT OUTER JOIN dbo.vwDrivers ON dbo.Stop.DriverID = dbo.vwDrivers.DriverID
LEFT OUTER JOIN dbo.truck ON dbo.Truck.TruckID = dbo.Stop.TruckID
INNER JOIN dbo.vwTicketIDFirstStopLastStop ON dbo.vwTicketIDFirstStopLastStop.TicketID = dbo.stop.ticketid
LEFT OUTER JOIN dbo.Company ON dbo.Company.CompanyID = dbo.vwTicketIDFirstStopLastStop.BillToCompanyID
Now it's this.
FROM dbo.Truck RIGHT OUTER JOIN
dbo.Stop INNER JOIN
dbo.StopType ON dbo.Stop.StopTypeID = dbo.StopType.StopTypeID LEFT OUTER JOIN
dbo.CityState ON dbo.Stop.City = dbo.CityState.City AND dbo.Stop.State = dbo.CityState.State LEFT OUTER JOIN
dbo.vwDrivers ON dbo.Stop.DriverID = dbo.vwDrivers.DriverID ON dbo.Truck.TruckID = dbo.Stop.TruckID LEFT OUTER JOIN
dbo.vwTicketIDFirstStopLastStop LEFT OUTER JOIN
dbo.Company ON dbo.Company.CompanyID = dbo.vwTicketIDFirstStopLastStop.BillToCompanyID ON dbo.vwTicketIDFirstStopLastStop.TicketID = dbostop.ticketid
No you cannot. That's why you should never, ever use it.
"Fx" means that the join is not a simple column-to-column link, but involves a function (that's also why it can't point to a field, of course). It should NOT do that by itself, though,
I hate the view GUI
I use RightClick->ScriptViewAs->Alter To->New Query Editor Window
So much nicer :)
It's the result of the view GUI parsing the SQL into it's own internal DOM style format and then writing it back out - much in the same way that HTML editors take in XHTML and emit stuff differently to how you wanted it :(