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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:23:28+00:00 2026-05-27T14:23:28+00:00

When I try to create this trigger, I get this exception: The name SITE_ID

  • 0

When I try to create this trigger, I get this exception:

The name "SITE_ID" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.

CREATE TRIGGER tr_VISITACTIVITY_insert ON VISITACTIVITY
INSTEAD OF INSERT AS
BEGIN

    INSERT INTO [VISITACTIVITY]
               ([O_ID]
               ,[SITE_ID]
               ,[VISIT_DATE]
               ,[STAFF]
               ,[VISIT_TYPE_ID]
               ,[COMMENTS]
               ,[DELETED])
         VALUES
               (-1
               ,SITE_ID
               ,VISIT_DATE
               ,STAFF
               ,VISIT_TYPE_ID
               ,VISIT_COMMENTS
               ,0
               )
    GO

END
GO

The insert that the programmer would issue in the application is something like this:

    INSERT INTO [VISITACTIVITY]
           ([SITE_ID]
           ,[VISIT_DATE]
           ,[STAFF_COMMENT]
           ,[VISIT_TYPE_ID]
           ,[COMMENTS]
           )
     VALUES
           (15
           ,'2011-08-08'
           ,'Eric, John'
           ,6
           ,'invasives growing along the border of the preserve'
           )

So, I need the values that the programmer provided in the insert to create the insert in the trigger.

How to I reference these values, then, in the trigger?

Thanks.

  • 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-27T14:23:29+00:00Added an answer on May 27, 2026 at 2:23 pm

    You need to look at the meta-table INSERTED, which is basically a table that contains all the data being inserted, so you’d reference (for example) SITE_ID as inserted.SITE_ID.

    What you also need to be careful of as well is doing single-row inserts from within the trigger (as you seem to be doing). If multiple rows are inserted in a batch, then INSERTED will contain multiple rows. So what you need to do is to use INSERT INTO table (...) SELECT ..., for example:

    INSERT INTO [VISITACTIVITY]
           ([SITE_ID]
           ,[VISIT_DATE]
           ,[STAFF_COMMENT]
           ,[VISIT_TYPE_ID]
           ,[COMMENTS]
       )
       SELECT VISITACTIVITY, SITE_ID, VISIT_DATE, STAFF_COMMENT, VISIT_TYPE_ID, COMMENTS
           FROM inserted
    

    By the way, reading your question, it looks like you’re just using the trigger to populate default values in a couple of columns. Have you considered just using a DEFAULT constraint on the table instead? For example, if you did the following:

    ALTER TABLE VisitActivity ADD CONSTRAINT DF_VisitActivity_Deleted DEFAULT (0) FOR DELETED
    ALTER TABLE VisitActivity ADD CONSTRAINT DF_VisitActivity_OID DEFAULT (-1) FOR O_ID
    

    …then this would make your example insert behave in the same way without the trigger. It depends whether you always want to override the values in Deleted or O_ID or not. If you always want to override, use a trigger – or better yet, stick a CHECK on the column to force it to a fixed value (will also highlight where your code is trying to change it as SQL Server will fail the insert due to referential integrity). If you want to be able to override it, then use DEFAULT constraints.

    (Of course, you may well have simplified the problem for the sake of the question, but I’m just highlighting how you can do this without resorting to a trigger).

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

Sidebar

Related Questions

I use squirrel 3.2.0 When I try to replace this trigger: CREATE OR REPLACE
In Delphi, is normal do this: ob = TObject.create; try //code finally ob.free; end;
i try to create a plpgsql trigger for postgresql 8.3 which automatically partitions a
I get Concurrent Modification Exception when i try to remove an item from HashMap.
Hi Is there any error in this TRIGGER Statement.When ever i try to run
I've been trying to get this working, and not having 100% success, basically trying
I try to create a new file inside a JSP and try to save
I try to create a thread in QT, can declare, create and start it,
I try to create a very simple app using windows API. I've done some
I try to create 2 buttons inside my app case WM_CREATE:{ hWnd =CreateWindowEx(NULL, LBUTTON,

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.