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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:42:57+00:00 2026-06-11T07:42:57+00:00

We have following requirement : Table1 : composite primary key version, id ———————————— version

  • 0

We have following requirement :

Table1: composite primary key version, id

------------------------------------
version   id     col1  coll2  active
------------------------------------
 1        123    'A'   'B'     'N'
 2        123    'C'   'D'     'Y'
 1        124    'E'   'F'     'Y'

Now for any insert and update on table1 for a given id, a new row should be created with the following attributes (derived by a trigger):

  1. Version should be incremented by 1 for given id and
  2. most current row should become active (active column is set to Y)

e.g.

INSERT INTO table1(id, col1, col2) VALUES (123, 'X', 'Y');

------------------------------------
version   id     col1  coll2  active
------------------------------------
 1        123    'A'   'B'     'N'
 2        123    'C'   'D'     'N'
 3        123    'X'   'Y'     'Y' 
 1        124    'E'   'F'     'Y'

3rd row is created

UPDATE table1 SET col1 = 'F' WHERE id = 124;

------------------------------------
version   id     col1  coll2  active
------------------------------------
 1        123    'A'   'B'     'N'
 2        123    'C'   'D'     'N'
 3        123    'X'   'Y'     'Y' 
 1        124    'E'   'F'     'N'
 2        124    'F'   'F'     'Y'

last row is created

DELETE FROM dbo.table1 WHERE id = 124;

------------------------------------
version   id     col1  coll2  active
------------------------------------
 1        123    'A'   'B'     'N'
 2        123    'C'   'D'     'N'
 3        123    'X'   'Y'     'Y' 
 1        124    'E'   'F'     'N'
 2        124    'F'   'F'     'N'

all rows for id 124 become inactive.

This seems to be modeling issue , but we are mandated to provide this feature using TABLE1 and supporting triggers.

We are not able to get around modifying the table issue as we need to select max(version)
and then insert into same table, Can anyone please suggest a workaround ?

  • 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-11T07:42:58+00:00Added an answer on June 11, 2026 at 7:42 am

    I don’t like the database design, it’s horrible, but you say you are stuck with it. How about using a view with INSTEAD OF triggers?

    1) Rename the table to e.g. TABLE1_BASE

    2) Create view TABLE1 as SELECT * FROM TABLE1_BASE

    3) Add an INSTEAD OF trigger like this:

    create trigger table1_io
    instead of insert or update or delete on table1
    for each row
    begin
      if inserting or updating then 
          update table1_base
          set active = 'N'
          where id = :new.id
          and active = 'y';
    
          insert into table1_base...;
      elsif deleting then
          update table1_base
          set active = 'N'
          where id = :old.id
          and active = 'y';
      end if;
    end;
    

    (Something like that)

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

Sidebar

Related Questions

I have the following requirement. I have a table with a column that contains
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have following requirement in my application. A tableView with games title After selecting
I am developing a network protocol In which I have following requirement each node
In my android application, I have following requirement. Activity A --> Activity B(Go to
In a web project using jsp, I have following requirement Upload a file (say
I have the following requirement. I submit a Model object to a view as
I have the following requirement: In C#2.0, Given a device configuration in xml format
I have the following requirement: Based on some user input, I need to generate
Helo. I have the following requirement: I have a list (ListView or Spinner depends

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.