The last table

Well, not really. Within a Data Pump SQL project it is called [dbo].[Last] and is primarily intended to be queried by third-party applications, like SCADA, EP, CEP or reporting tools. The table contains only one row with the latest serial number and the time-stamp from the [dbo].[PartData] table. Here is a typical example:

ID Val TimeUTC TimeLoc
1 200805151007 2008-05-15 14:30:01 2008-05-15 10:30:01

 

The table structure may vary, depending on the project. Time column in UTC allows for applications outside of the time zone.

Column Name Data Type Description
ID int ID column for this table; always 1 (one row only).
Val bigint Serial number of the last entry from [dbo].[PartData].
TimeUTC datetime Time-stamp of the last entry in UTC (GMT).
TimeLoc datetime Optional. Local time of the last entry.

 

The “third-party” application should query the [dbo].[Last] table and determine if there were any changes to the [dbo].[PartData] table since the last query.

SELECT [Val], [TimeLoc] 
    FROM [dbo].[Last] WHERE ID = 1;

Once a change is detected, it is OK to query the [dbo].[PartData] table.

    
/* Time of the last query */
DECLARE @LastTime datetime;
SET @LastTime = '2008-05-15 14:30:01';
--
/* Query the table */
SELECT * 
    FROM [dbo].[PartData]
WHERE [RecordDate]  >= @LastTime;