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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:20:13+00:00 2026-06-08T01:20:13+00:00

Hello i created a SQL Trigger which copies the edited row and set a

  • 0

Hello i created a SQL Trigger which copies the edited row and set a new ID. There is another table which is connected by the ids. its hard for me to explain i give you an example:

Table 1 with the Products:

ID           BEZEICHNUNG            PREIS

45           Coffee                 5,60
46           Tea                    2,20

Table 2 with the connection from Room to the Products:

ProductID          RoomID
45                 11
45                 46
46                 48
46                 41

When i update the price of the first row from Table 1, the Trigger creates a new row with a new ID like this:

ID           BEZEICHNUNG            PREIS

45           Coffee                 5,60
46           Tea                    2,20
47           Coffee                 4

My goal is to insert to the table 2 the new id with all the room ids which belongs to the old row.

It should look like this:

ProductID          RoomID
45                 11
45                 46
46                 48
46                 41
47                 11
47                 46

My current trigger look like this:

ALTER TRIGGER [dbo].[DIENSTLEISTUNG_UPDATE]
   ON [dbo].[DIENSTLEISTUNG]
   INSTEAD OF UPDATE
AS
BEGIN
      SET  NOCOUNT ON;

    INSERT INTO [DIENSTLEISTUNG] (BEZEICHNUNG, MENGENEINHEIT, 
        PREIS, BESCHREIBUNG, VORLAUFZEIT,
        AZ_MO, AZ_DI,AZ_MI,AZ_DO,AZ_FR,
        AZ_SA,AZ_SO,DIENSTLEISTUNGSART_ID,
        UPDATE_USER, UPDATE_DATE, RUESTZEIT,
        PERMISSIONS, KONTRAKTPOSITION,ARTIKELNUMMER,
        ANZAHL, BUCHUNGSHINWEIS, SONDERWUNSCH,FLAG)

    SELECT  BEZEICHNUNG, MENGENEINHEIT, 
        PREIS, BESCHREIBUNG, VORLAUFZEIT,
        AZ_MO, AZ_DI,AZ_MI,AZ_DO,AZ_FR,
        AZ_SA,AZ_SO,DIENSTLEISTUNGSART_ID,
        UPDATE_USER,GETDATE(),RUESTZEIT,
        PERMISSIONS, KONTRAKTPOSITION,ARTIKELNUMMER,
        ANZAHL, BUCHUNGSHINWEIS, SONDERWUNSCH,
        0 
    FROM INSERTED

    UPDATE  DIENSTLEISTUNG
    SET     FLAG = 1 
    FROM    DIENSTLEISTUNG 
            INNER JOIN INSERTED
                ON INSERTED.ID = DIENSTLEISTUNG.ID
SET  NOCOUNT OFF;      
END
  • 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-08T01:20:14+00:00Added an answer on June 8, 2026 at 1:20 am

    In the trigger, after the insert add

     SELECT @intNewID = Scope_Identity()  
    

    This gets the ID of the newly inserted product

     INSERT table2 (ProductID, RoomID)  
     SELECT @intNewID, RoomID
     FROM deleted
          INNER JOIN table2 on deleted.productid=table2.productid
    

    This gets the products linked to the old product from the deleted, and copies them

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

Sidebar

Related Questions

Hello i have a SQL Table which look like this: ID BEZEICHNUNG PREIS UPDATE_DATE
Hello I`ve created simple WFC DataService and connected entit model with my database. This
I created a simple hello-wordish code using hibernate sf = new Configuration().configure().buildSessionFactory(); System.out.println(sessionFactory is
Hello Stackoverflowers! I created a simple sqlite DB like so. //event table name private
Hello I have created and application which contains a gridview that is populated by
Hello I'm essentially trying to do this inside a new view window in SQL
Hello, I have the following sql table + data: CREATE TABLE IF NOT EXISTS
Hello I'm trying to insert some XML data into a table on SQL Server
SQL Server 2008 Hello. New templates I create in Template explorer are not showing
hello friends i created struts with hibernate application when i call SessionFactory sessionFactory =new

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.