Click here to monitor SSC

MS SQL Trigger Problem/Limitations

Last post 12-10-2008, 9:52 AM by Arles. 1 replies.
Sort Posts: Previous Next
  •  08-11-2008, 5:38 AM Post number 67716

    • baddy is not online. Last active: 10-30-2008, 5:49 AM baddy
    • Top 50 Contributor
    • Joined on 04-07-2008
    • India
    • Blue Gene

    MS SQL Trigger Problem/Limitations

    Hi  –

    I want to insert/update/delete records into some other table a (say history table). & for this I'm using triggers

    Firstly I tried instead of TRIGGER for insert, delete & update statements, as instead of triggers doesn’t support for the table having FOREIGN KEY with cascading DELETE or UPDATE

    So i created After Trigger to captures these insert/update/delete statements, in after triggers, SQL Server does not allow text, ntext, or image column references in the inserted and deleted tables. As we are capturing the events (insert/update/delete) data from these two logical tables inserted and deleted.

    As my table have BLOB (image, text, text) variables. I can't change the DB schema. I have to do something using Triggers…

    But In both cases there is limitation i.e.

    INSTEAD OF TRIGGER – doesn’t support table having cascading.

    AFTER TRIGGER – doesn’t allow text, ntext, image column references in the inserted and deleted.

     

    Any Suggestion Please…!

     

    Thanks in advance,

    Baddy

     


    Thanks,
    Baddy
  •  12-10-2008, 9:52 AM Post number 70827 in reply to post number 67716

    • Arles is not online. Last active: 02-23-2011, 7:26 AM Arles
    • Top 25 Contributor
    • Joined on 10-20-2008
    • Nashville, TN
    • Celeron 450

    Re: MS SQL Trigger Problem/Limitations

    Here’s thinking out of the box --- have you thought of doing away with the “history” table entirely?  A properly indexed and tuned database should hold, retrieve and update several million rows of historical data without sweating.  Now the question would be, “Well, how do I retrieve the most current record set?”  If you have a date/time stamp and primary key in every table you can couple that with SQL functions like MAX and RANK which should answer your need to retrieve just the most current record set.

     

    The other option is to rewrite your TRIGGERS into STORED PROCEDURES.  Your “transaction” (table where you keep your current data) would more than likely be identical in structure to your history table, then it’s just a matter of rewriting your STORED PROCEDURES to work with your “history” table.  The advantage of course is that all your cascading updates and deletes will work and more importantly you can easily ROLLBACK your transactions in your STORED PROCEDURES.

     

    I hope this gives you an added perspective on how to address this issue from a different angle.

     

    Arles

View as RSS news feed in XML