SELECT t.Name,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
sys.partitions p ON t.object_id = p.OBJECT_ID
INNER JOIN
sys.allocation_units a ON p.partition_id = a.container_id
GROUP BY t.Name
HAVING SUM(a.used_pages) > 0
ORDER BY TotalSpaceKB Desc
No words wasted! Getting to the point about the work I do, the problems I deal with, and some links to posts about where I work.
Translate
Friday, December 19, 2025
TSQL - Simple Table Size Query
Simple query for table size information.
Thursday, July 24, 2025
TSQL - Set A Variable While Updating
I needed to set the value in a variable and update a field at the same time This is the update query.
DECLARE @numberOfCountersNeeded as int;
DECLARE @newcounterval as bigint;
SET @numberOfCountersNeeded = 3
UPDATE c --get the counter interval and update the current count
SET @newcounterval = somefield = somefield + @numberOfCountersNeeded
FROM sometable c
WHERE conditions
Friday, July 4, 2025
TSQL - Delete Duplicate Rows
This was the solution to a problem that was posted on Reddit. The OP asked how to delete a duplicate row. In the question, they just needed to delete a single duplicate. But then I wondered about cases where there was more than a single duplicate. In the example, EmployeeID is the primary key.
This is the finale SQL:
This is the finale SQL:
DECLARE @nC int; --number of records to delete
DECLARE @id int = 5; --key
SELECT @nc = count(*)-1 from [dbo].[TestTable]
WHERE EmployeeID = @id
DELETE top (@nc) from [dbo].[TestTable]
WHERE EmployeeID = @id
Monday, March 3, 2025
Salesforce - Error When Testing an Email in Flow
I was working on a flow in Salesforce and I was get an error in the email template. The error was: Error Occurred: We don't recognize the field prefix Opportunity. Associate a record that matches the prefix or update the template to remove the merge field from the body, subject, or letterhead. The error occured because I didn't have the Related Record ID set on the Send Email element.
Subscribe to:
Comments (Atom)
