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 556087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:52:58+00:00 2026-05-13T11:52:58+00:00

I have created an INSTEAD OF INSERT trigger on a view in my database.

  • 0

I have created an INSTEAD OF INSERT trigger on a view in my database. I want to know which columns are included in the column list of the INSERT statement on the view.

If you read the MSDN documentation for triggers the UPDATE() and COLUMNS_UPDATED() functions should satisfy this requirement. However, during my testing I found that regardless of what columns are in the INSERT column list the UPDATE() and COLUMNS_UPDATED() functions always return all columns from the view.

CREATE VIEW dbo.MyView (BatchId, [Status], OrderNumber, WhenClosed) AS
    SELECT bth.BatchId, bth.[Status], bth.OrderNumber,
            Private.ufxAdjustDateTime(bth.WhenClosed, bth.WhenClosedUtcOffset)
        FROM Private.Batch AS bth
GO
CREATE TRIGGER dbo.[MyView-Insert] ON dbo.MyView INSTEAD OF INSERT AS
BEGIN
    SET NOCOUNT ON

    DECLARE @batchIdIsSet BIT

    SELECT @batchIdIsSet = 0
    IF UPDATE(BatchId)
        SELECT @batchIdIsSet = 1

    INSERT INTO Private.Batch
        (BatchId, [Status], OrderNumber)
        SELECT CASE @batchIdSet
                   WHEN 1 THEN ins.BatchId
                   ELSE NEWID()
               END, ins.[Status], ins.OrderNumber
            FROM inserted AS ins
END

The reason I want to do this is that I need to modify an existing table and I have loads of legacy code that relies on it. So what I’ve done is created a new table, changed the old table to a view and created triggers, on the view, to allow INSERT, UPDATE and DELETE statements.

Now, the old table had defaults for certain columns, if the insert into the view uses the default I want to use a default in my insert into the new table. To do this I have to be able to figure out which columns had values [explicitly] supplied for the INSERT.

Checking to see if the column has NULL is not enough because the INSERT statement can explicitly set the field value to NULL and this is perfectly acceptable.

Hmmm, I hope this is clear.
Kep.

  • 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-13T11:52:58+00:00Added an answer on May 13, 2026 at 11:52 am

    On an INSERT statement, every column is affected. It either gets NULL, or the value you’re specifying.

    Checking for NULL would be the best option, but as you can’t do that, I’m thinking you might be a bit stuck. Can you work out scenarios which might need to handle NULL explicitly?

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

Sidebar

Ask A Question

Stats

  • Questions 266k
  • Answers 266k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Convention is to put static media in either media/appname/ or… May 13, 2026 at 12:39 pm
  • Editorial Team
    Editorial Team added an answer What about using the OpenCV library for Processing? Technically, Processing… May 13, 2026 at 12:39 pm
  • Editorial Team
    Editorial Team added an answer $("#myElement").click(function() { $(this).siblings(":last").hide(); }); May 13, 2026 at 12:39 pm

Related Questions

I have a table where I created an INSTEAD OF trigger to enforce some
I have a problem with compiling an Oracle trigger via SQL*PLUS - I don't
I am making changes to an existing database while developing new software. There is
OK, I have a table with no natural key, only an integer identity column
We have a user table, every user has an unique email and username. We

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.