Possible as ANSI SQL?

From: kmbarz (kmbarz_at_discussions.microsoft.com)
Date: 11/03/04


Date: Wed, 3 Nov 2004 15:32:01 -0800

I have a coworker who is working on an application that currently interacts
with SQL server. He would like to be able to port the application to other
databases as well. One of the key functions is for this thing to be able to
generate tables and corresponding audit trail tables. Currently in SQL,
we're using this for our audit tables:

CREATE TRIGGER trgInsertTbl_ConcomitantMedication
ON tbl_ConcomitantMedication
FOR INSERT
AS

-- Code to declare, set and write tblBaseline values to auditbaseline --
ALTER TABLE tbl_ConcomitantMedication_Audit
Disable TRIGGER trgProtectTbl_ConcomitantMedication_audit

INSERT INTO tbl_ConcomitantMedication_Audit
SELECT i.*, 'INSERT', CURRENT_TIMESTAMP, SYSTEM_USER
FROM inserted i

ALTER TABLE tbl_ConcomitantMedication_audit
Enable TRIGGER trgProtectTbl_ConcomitantMedication_audit

Is there some way to generalize this so it will work on anything? If not,
any idea of how many different versions he might need?
Thanks



Relevant Pages

  • Re: Records not inserting...
    ... > I am totally new to SQL server. ... However, in a trigger, would I be ... test the effects of certain data modifications and to set conditions for ... UPDATE statements. ...
    (microsoft.public.sqlserver.odbc)
  • Re: Help for an Oracle Newbie
    ... application I wrote using SQL Server ported over to Oracle. ... Obviously there are several built in data types in SQL Server that do ... Of course I had to use a different name for the trigger under each ...
    (comp.databases.oracle.server)
  • Re: TRIGGER (AFTER INSERT) and Store Procedure ... insert failed !
    ... >into SQL server, the record exist anyway! ... >If you refresh the data you will see the record... ... it gets refreshed after trigger excecution automatically. ... I don't know your monitoring system, but I guess that removing the result ...
    (microsoft.public.sqlserver.programming)
  • Re: Problem altering table and adding a default
    ... ALTER TABLE dbo.Test_tbl ADD Notnull_col1 charNOT NULL ... SQL Server does not allow that - you can only add nullable columns. ... After you add a new column in Enterprise Manager, uncheck Allow Nulls, bind the uder- ... Start Profiler and perform a new trace. ...
    (microsoft.public.sqlserver.server)
  • Re: Problem altering table and adding a default
    ... SQL Server does not allow that - you can only add nullable ... > After you add a new column in Enterprise Manager, uncheck Allow Nulls, ... the ALTER TABLE statement above will pass to the SQL Server ... > 4) Start Profiler and perform a new trace. ...
    (microsoft.public.sqlserver.server)