Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6254345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:09:51+00:00 2026-05-24T14:09:51+00:00

I tried create a trigger: CREATE TRIGGER DataTrigger ON Data AFTER INSERT , DELETE

  • 0

I tried create a trigger:

CREATE TRIGGER DataTrigger ON Data AFTER INSERT , DELETE
AS
BEGIN
IF EXISTS(SELECT * FROM Inserted)

INSERT INTO [dbo].[AuditTrail]
       ([ActionType]
       ,[TableName]
       ,[Name]
       ,[Time])

('INSERT'   //Incorrect syntax near 'INSERT'
    ,'Data' 
    ,SELECT col1 FROM Inserted
    ,CURRENT_TIMESTAMP  //Incorrect syntax near the keyword 'CURRENT_TIMESTAMP')
END

but it keep saying that I have thoes errors, can somebody show me where I did wrong?

P/S: what is the best way to detect an update?
Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:09:53+00:00Added an answer on May 24, 2026 at 2:09 pm
    CREATE TRIGGER DataTrigger ON Data AFTER INSERT , DELETE
    AS
    BEGIN    
      INSERT INTO [dbo].[AuditTrail]
           ([ActionType]
           ,[TableName]
           ,[Name]
           ,[Time])
      SELECT 'INSERT'  
        ,'Data' 
        ,col1
        ,CURRENT_TIMESTAMP
      FROM Inserted
    
    END
    

    Just for clarification.

    Your query, if syntatically correct would have failed if more than one row was inserted, the version above allows for multiple inserts.

    The IF EXISTS was redundant, which is why it was removed, if there are no rows there will be no insert into your audit table.

    If you want to audit DELETE you’ll need a similar statement again, but using the Deleted table rather than Inserted

    To audit UPDATE, create a new trigger, for each updated row you get an entry in Inserted with the new updates and an entry in Deleted with the old data, you can join these if you want to track old and new.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to create a database by the following command: mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP, ->
I tried writing this small trigger in MySQL, CREATE TRIGGER `leg` BEFORE INSERT ON
how to create a shortcut for a exe from a batch file. i tried
I ran into a problem as I tried to create two TIMESTAMP columns in
I tried using the following but apparently it's invalid SQL: CREATE OR REPLACE TRIGGER
UPDATE 3: I created a Visual Studio 2008 test project and tried to create
I am very, very new to MYSQL.I tried to create a table named option.
I have tried to find how to create DLL-s on linux using google, but
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
I have to create a trigger (not procedure) to update subtotal, shipping_charge, tax and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.