Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

SQL Triggers?

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

Name: Anonymous 2012-04-25 16:30

Trigger is like a tricky nigger

Name: Anonymous 2012-04-25 16:32

>>2
this right fucking here

>that feel when you spend all day trying to figure out what is wrong with your program, then you find out it's a trigger on one table fucking shit up

Name: Anonymous 2012-04-25 16:45

>>2
Epicly put, fine sir
>>3
dat feel, dat feel

Name: bampu pantsu 2012-05-29 4:38

bampu pantsu

Don't change these.
Name: Email:
Entire Thread Thread List