| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is a public repo that contains SQL statements that are helpful in the day to day administration of Rock.
To find a script you're interested in either select the directory that best matches what you're looking for, or use Github's search feature by typing t and a keyword.
SQL can be dangerous as it's outside of the castle wall. In Rock the C# models provide things like data integrity checks and business logic validation. They also are much less prone to breaking changes. SQL in Rock should be used for administration and on rare cases reporting, but only after all other reporting options have been considered. The goal of this repo is in no way an encouragement to add more dynamic SQL reports in your environment. To do so would be to add more risk to the day-to-day operations of your reporting strategy.
The goal of this repo is not to provide a list of every SQL script imaginable, but rather a highly curated list of generally helpful and quality written SQL. If you have such a script feel free to send a PR. We will be selective of what we add, so please don't expect every PR to be accepted. Scripts not matching the style guide rules below will be rejected.
Scripts should be placed into a directory with the Rock domain as the folder name. Not sure what domain to use? Look for the directory name that the related block might be under. Some domains will have sub-directories if we feel like it could have multiple scripts. For instance the Interactions directory has a sub-directory for scripts around Page Views.
-- =====================================================================================================
-- Author: Jon Edmiston
-- Create Date: 3/21/2020
-- Description: Displays page load times for a specified page. Also displays who loaded the page if
-- known.
-- Note: Time is in seconds.
--
-- Change History:
-- 3/22/2020 Jon Edmiston: Updated SQL to allow passing in Page Id vs having to know ComponentId.
-- =====================================================================================================
DECLARE @PageId int = 1247 -- Id of the page you want timings from.
DECLARE @MaxRows int = 1000 -- The maximum number of rows to return.
DECLARE @DaysBack int = 1 -- The number of days back to look.
-------------------------------------------------------------------------------------------------------
SET @DaysBack = @DaysBack * -1
DECLARE @StartDate datetime = (SELECT DATEADD (day , @DaysBack , GETDATE() ) )
------------------------------
SELECT
TOP (@MaxRows)
[InteractionTimeToServe]
, [InteractionDateTime]
, ISNULL( p.[NickName], '') [First Name]
, ISNULL( p.[LastName], '') [Last Name]
FROM
[Interaction] i
INNER JOIN [InteractionComponent] ic ON ic.[Id] = i.[InteractionComponentId]
LEFT OUTER JOIN [PersonAlias] pa ON pa.[Id] = i.[PersonAliasId]
LEFT OUTER JOIN [Person] p ON p.[Id] = pa.[PersonId]
WHERE
ic.[EntityId] = @PageId
AND [InteractionTimeToServe] IS NOT NULL
AND [InteractionDateTime] > @StartDate
ORDER BY [InteractionTimeToServe] DESC
Be careful with queries that could ADD/UPDATE/DELETE data. You might consider a pattern like this for deletes.
DECLARE @InteractionChannel int = 23 SELECT * --DELETE FROM [Interaction] WHERE [InteractionComponentId] IN (SELECT [Id] FROM [InteractionComponent] WHERE [InteractionChannelId] = @InteractionChannel)
Note that if the individual runs this query it will initiall show them what would be deleted. They have to modify it a bit to actually perform the delete.
| Back | FazBrowse Home | New Git URL |