Name: Anonymous 2012-04-25 15:52
Hey /prog/,
new to SQL triggers. Having a little trouble at the moment, not sure if I'm doing it correctly. Could anyone guide me? Firstly I'm trying to order the threads from newest to oldest every insert/update and then when the thread count is above 5 the oldest would be removed from the table. Here's what I got so far,
CREATE TRIGGER handleThreads AFTER UPDATE, INSERT ON Threads
SELECT * FROM Threads
ORDER BY update_time DESC
DECLARE @ThreadCount int
SET @ThreadCount = (SELECT COUNT(*) FROM Threads);
IF @ThreadCount > 5
FOR EACH ROW BEGIN
DELETE FROM Threads WHERE order_ID > 5
END
END;
Thanks in advance guise
new to SQL triggers. Having a little trouble at the moment, not sure if I'm doing it correctly. Could anyone guide me? Firstly I'm trying to order the threads from newest to oldest every insert/update and then when the thread count is above 5 the oldest would be removed from the table. Here's what I got so far,
CREATE TRIGGER handleThreads AFTER UPDATE, INSERT ON Threads
SELECT * FROM Threads
ORDER BY update_time DESC
DECLARE @ThreadCount int
SET @ThreadCount = (SELECT COUNT(*) FROM Threads);
IF @ThreadCount > 5
FOR EACH ROW BEGIN
DELETE FROM Threads WHERE order_ID > 5
END
END;
Thanks in advance guise