Resources
  • Introduction
  • ASP.NET
    • F#
    • C#
    • .NET Core
    • MSBuild
    • Tools
  • (T-)SQL
    • Snippets
  • Typescript
  • Javascript
    • Angular
    • React - Redux
    • Stats
  • Progressive Web Apps
  • Design and UX
    • HTML
    • CSS - Cascading Style Sheets
  • Computer Science
    • Architecture and Patterns
    • Database
  • Security
  • Testing
  • Hacking and Tinkering
  • Tools
  • CLI Cheat Sheets
    • Git
    • Dotnet core
    • Docker for Windows
    • Powershell
  • Progressive Web Apps
  • Miscellaneous
Powered by GitBook
On this page

Was this helpful?

  1. (T-)SQL

Snippets

Check row count twice with pause in between checks to see if row count increases in any tables

DECLARE @RowCounts TABLE(
  TableName sysname NOT NULL,
  RecordsPre INT NOT NULL,
  TimestampPre DateTimeOffset NOT NULL,
  RecordsPost INT NULL,
  TimestampPost DateTimeOffset NULL
);

INSERT INTO @RowCounts (TableName, RecordsPre, TimestampPre)
SELECT T.name TableName, I.rows Records, GETDATE() CurrentTime
FROM sysobjects T, sysindexes I
WHERE T.xtype = 'U' and I.id = T.id and I.indid IN (0,1)

WAITFOR DELAY '00:00:15'

UPDATE A
SET RecordsPost = B.Records,
    TimestampPost = B.CurrentTime
FROM (
  SELECT T.name TableName, I.rows Records, GETDATE() CurrentTime
  FROM sysobjects T, sysindexes I
  WHERE T.xtype = 'U' and I.id = T.id and I.indid IN (0,1)
) B
INNER JOIN @RowCounts A
ON A.TableName = B.TableName

SELECT *
FROM @RowCounts
ORDER BY TableName
Previous(T-)SQLNextTypescript

Last updated 5 years ago

Was this helpful?