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

The Archive Base Latest Questions

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

Here’s a good one I think. To start off with, I don’t really know

  • 0

Here’s a good one I think. To start off with, I don’t really know what a trigger is, which might become obvious now.

Are triggers good for maintaining backwards compatibility between database schemas?

Say I have a 1-to-many relationship in version 1. In version 2 this has been changed to a many-to-many. Would a properly implemented trigger be able to handle this so as to allow both versions to run on the same database? Is it a good idea?

  • 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-23T15:45:28+00:00Added an answer on May 23, 2026 at 3:45 pm

    Yes, you could do this by utilizing a INSTEAD OF trigger for inserts, updates, and deletes on a view for the old version. To make this more clear, let’s consider the following example:

    v1:
        A(id int, data varchar(30))
        B(id int, a_id int, data varchar(30))
    
    v2:
        A(id int, data varchar(30))
        B(id int, data varchar(30), data2 varchar(20))
        AB(a_id int, b_id int)
    

    First you would create a view to mimic the old version of the B table. The tricky thing would be deciding on which of the AB relations to show to the old application. One option would be to add a primary_b column of type bit to the AB table. The view below uses this option

    CREATE VIEW OldB AS 
        SELECT B.id AS id, AB.a_id AS a_id, B.data AS data,  
        FROM B INNER JOIN AB ON B.id = AB.b_id
        WHERE AB.primary_b = 1
    

    Next you would create triggers on the view to handle inserts and updates.

    CREATE TRIGGER InsertTrigger on OldB INSTEAD OF INSERT
    AS
    BEGIN
    
    INSERT INTO B (id, data) SELECT id, data FROM inserted;
    UPDATE AB SET primary_b = 0 WHERE b_id IN (SELECT id FROM inserted);
    INSERT INTO AB (a_id, b_id, primary_b) SELECT a_id, id, 1 FROM inserted;
    
    END 
    GO
    

    You would do something similar for instead of update, except that you would have to manage the change in A to B links by deleting and adding rows in AB. I haven’t checked this code out for errors yet, but I will in the next hour or so and post an update if needed.

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

Sidebar

Related Questions

Here a simple question : What do you think of code which use try
Here is my code, which takes two version identifiers in the form 1, 5,
Here is my code sample, let me know if it can be further improved?
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY
Here is an example: I have a file 1.js, which has some functions. I
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote

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.