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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:17:22+00:00 2026-06-07T17:17:22+00:00

I am using SQL Server 2012 I have a table called AMOUNTS and a

  • 0

I am using SQL Server 2012

I have a table called AMOUNTS and a table called AMOUNTS_HIST

Both tables have identical columns:

  1. CHANGE_DATE
  2. AMOUNT
  3. COMPANY_ID
  4. EXP_ID
  5. SPOT
  6. UPDATE_DATE [system date]

The Primary Key of AMOUNTS is COMPANY_ID and EXP_ID.
The Primary Key pf AMOUNTS_HIST is COMPANY_ID, EXP_ID and CHANGE_DATE

Whenever I add a row in the AMOUNTS table, I would like to create a copy of it in the AMOUNTS_HIST table. [Theoretically, each time a row is added to ‘AMOUNTS’, the COMPANY_ID, EXP_ID, CHANGE_DATE will be unique. Practically, if they are not, the relevant row in AMOUNTS_HIST would need to be overridden. The code below does not take the overriding into account.]

I created a trigger as follows:

CREATE TRIGGER [MYDB].[update_history] ON [MYDB].[AMOUNTS]
FOR UPDATE
AS
INSERT MYDB.AMOUNTS_HIST (
    CHANGE_DATE,
    COMPANY_ID,
    EXP_ID,
    SPOT
    UPDATE_DATE
    )
SELECT e.CHANGE_DATE,
    e.COMPANY_ID,
    e.EXP_ID
    e.REMARKS,
    e.SPOT,
    e.UPDATE_DATE
FROM MYDB.AMOUNTS e
JOIN inserted ON inserted.company_id = e.company_id
    AND inserted.exp_id=e.exp_id

I don’t understand why it does nothing at all in my AMOUNTS_HIST table.
Can anyone help?

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-06-07T17:17:23+00:00Added an answer on June 7, 2026 at 5:17 pm

    I just wanted to chime in. Have you looked at CDC (change data capture).

    http://msdn.microsoft.com/en-us/library/bb522489(v=sql.105).aspx
    “Change data capture is designed to capture insert, update, and delete activity applied to SQL Server tables, and to make the details of the changes available in an easily consumed relational format. The change tables used by change data capture contain columns that mirror the column structure of a tracked source table, along with the metadata needed to understand the changes that have occurred.

    Change data capture is available only on the Enterprise, Developer, and Evaluation editions of SQL Server.”

    As far as your trigger goes, when you update [MYDB].[AMOUNTS] does the trigger throw any errors?

    Also I believe you can get all your data from Inserted table without needed to do the join back to mydb.amounts.

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

Sidebar

Related Questions

Using SQL Server 2012 Express. I have a table which represents key/value pairs. keycol
We have an issue upgrading to SQL Server 2012. I am using the following
[using SQL Server 2005] I have a table full of users, I want to
Using SQL Server 2008, I have abc and xyz table abc abc_id | xyz_id1
Using SQL Server 2008 (R2). I have two tables in different databases (with same
Using SQL Server 2K8 R2, I have two related tables - Member and Questionnaire.
Using SQL Server 2005, I have a table where certain events are being logged,
Using SQL Server I want to check two values in two table. I have
I am using SQL Server 2008 and I have 4 tables StudentAbsentees, Students, StudentSections
Im using sql server 2012 and its replication feature. Here im trying to manually

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.