Hi
You can create a trigger that does the job (UNTESTED)
CREATE TRIGGER my_trig ON Mytable FOR INSERT
AS
DELETE FROM myTable WHERE EXISTS (SELECT * FROM inserted I WHERE
I.Identifier=myTable.Identifier
AND myTable.InsertTime< I.InsertTime AND myTable.Duration< I.Duration)
Or if you do that throu a stored procedure
DECLARE @dt DATETIME, @Duration INT
SET @dt =GETDATE()
SET @Duration=20
DELETE FROM myTable WHERE InsertTime<@dt AND Duration<@Duration
SELECT * FROM myTable
> Hi
> Can you please post DDL + sample data + an expected result?
[quoted text clipped - 39 lines]
>
> - Show quoted text -
Hi Uri,
All that I have so far is:
USE myDatabase
CREATE TABLE myTable
(
Identifier INT IDENTITY NOT NULL,
InsertTime DATETIME NOT NULL,
Duration INT NOT NULL
)
Example of data would be like the above:
12342 20/03/08 11:12:23.323 30
with the constraint that when the system time value exceed "InsertTime
+ Duration" - the row and all child depends are removed. Does this
help any?
Sean - 20 Mar 2008 14:47 GMT
The only problem with that Uri is that in the case that a time is
inserted into the table say
123456 20/03/2008 09:00:00.000 5
it would expire at 9:05 am on March 20th. Using the trigger option
could lead to nothing being inserted for a random amount of time, and
in this case possibly longer than 5 minutes. Thus the row would be
left in there for an undeterminable amount of time, thus whatever the
time limit is for would be null and void logically but as far as the
application is concerned it's still there and valid.
It would be nice to use the triggers, but I think pulling the data
from a view like suggested above would work much better. I would take
that suggesstion by Rick except depending on how many rows are
inserted per day, possibly running the sproc every x hours or so. It
all depends on the workload in that table.
-Sean
> Hi
> You can create a trigger that does the job (UNTESTED)
[quoted text clipped - 19 lines]
>
> SELECT * FROM myTable
Uri Dimant - 20 Mar 2008 15:01 GMT
Sean
I see what you mean. That we need addition check within a trigger and not
to simple DELETE. What to check?
But perhaps the OP wants those rows left in the table ?
The only problem with that Uri is that in the case that a time is
inserted into the table say
123456 20/03/2008 09:00:00.000 5
it would expire at 9:05 am on March 20th. Using the trigger option
could lead to nothing being inserted for a random amount of time, and
in this case possibly longer than 5 minutes. Thus the row would be
left in there for an undeterminable amount of time, thus whatever the
time limit is for would be null and void logically but as far as the
application is concerned it's still there and valid.
It would be nice to use the triggers, but I think pulling the data
from a view like suggested above would work much better. I would take
that suggesstion by Rick except depending on how many rows are
inserted per day, possibly running the sproc every x hours or so. It
all depends on the workload in that table.
-Sean
> Hi
> You can create a trigger that does the job (UNTESTED)
[quoted text clipped - 19 lines]
>
> SELECT * FROM myTable
almurph@altavista.com - 20 Mar 2008 17:49 GMT
> Sean
> I see what you mean. That we need addition check within a trigger and not
[quoted text clipped - 46 lines]
>
> - Show quoted text -
Gentlemen,
I appreciate your posts. I'm leaning toward a View instead of a
table but won't I have to use a trigger on the view as well? Or is
there something I'm missing?
Slightly confused,
Al.
Sean - 20 Mar 2008 18:37 GMT
No - you wouldn't use a trigger at all.
Create teh view off of the underlying tables as suggested by Rick.
Once that's done, create a stored procedure also as Rick suggests that
deletes the values out of the underlying tables and then schedule that
stored procedure to run every so often, daily, hourly, whatever you
think is necessary.
the view will take care of which ones should and shouldn't show up and
the stored procedue will run cleanup whenever it's fired.
On Mar 20, 12:49 pm, "almu...@altavista.com" <almu...@altavista.com>
wrote:
> > Sean
> > I see what you mean. That we need addition check within a trigger and not
[quoted text clipped - 60 lines]
>
> - Show quoted text -