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

  • SEARCH
  • Home
  • 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 223411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:13:07+00:00 2026-05-11T19:13:07+00:00

I wish to make a trigger but i’m not sure how to grab the

  • 0

I wish to make a trigger but i’m not sure how to grab the data for whatever caused the trigger.

I have a simlpe table.

FooId INT PK NOT NULL IDENTITY
Name VARCHAR(100) NOT NULL

I wish to have a trigger so that when an UPDATE, INSERT or DELETE occurs, i then do the following.

Pseduocode

IF INSERT
    Print 'Insert' & Name
ELSE IF UPDATE
    Print 'Update' & FooId & Name
ELSE IF DELETE
    Print 'Delete' & FooId & Name

Now, I know how to make a trigger for a table.
What i don’t know how to do is figure out the values based on what the trigger type is.

Can anyone help?

Edit: Not sure if it helps, but db is Sql Server 2008

  • 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-11T19:13:08+00:00Added an answer on May 11, 2026 at 7:13 pm

    the pseudo table “inserted” contains the new data, and “deleted” table contains the old data.

    You can do something like

    create trigger mytrigger on mytable for insert, update, delete
    as
        if ( select count(*) from inserted ) > 0
            -- insert or update
            select FooId, Name from inserted
        else
            -- delete
            select FooId, Name from deleted
    

    To clarify all the comments made by others, on an insert, the inserted table contains data and deleted is empty. On a delete, the situation is reversed. On an update, deleted and inserted contain the “before” and “after” copy of any updated rows.

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

Sidebar

Related Questions

I wish to make sure that my data has a constraint the following check
I have a large system that I have coded and I wish to make
I have some REST web services implemented in WCF. I wish to make these
Several articles and blogs I have read suggest placing assemblies I wish to make
i have a wall on each profile, and i wish to make it smarter,
I have a custom slider-type object, that I wish to make more usable. Currently
I have several variables coming from an array in $POST_['array'] i wish to make
I have an RMI application that have multiple Peers. I wish to make use
i'm looking three20 and I wish make this thing: use a TTWebController but implement
I wish to make a cosine table at compile time. Is there a way

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.