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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:24:11+00:00 2026-06-13T14:24:11+00:00

When I perform an task, two rows gets inserted in my table ie. duplication.

  • 0

When I perform an task, two rows gets inserted in my table ie. duplication. I need to remove the duplicate by using an after insert trigger. I need to delete one duplicate record from those 2. I need something like this

CREATE TRIGGER del_rec
INSERT ON table1
AFTER(EXECUTE PROCEDURE del_proc());

CREATE PROCEDURE del_proc()

//check field a,b,c of this table already exists for this id. if yes delete the second one

END PROCEDURE;

For example:

table 1:

a b c d e
1 1 1 2 2
1 1 1 2 2

it should delete the second row.

  • 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-13T14:24:12+00:00Added an answer on June 13, 2026 at 2:24 pm

    Your table is misdesigned if duplicates can be inserted into it. You should have a unique constraint ensuring that it does not happen.

    Assuming that you can’t fix the table for some reason, then:

    CREATE TRIGGER ins_table1
        INSERT ON table1 REFERENCING NEW AS new
        FOR EACH ROW (EXECUTE PROCEDURE ins_table1(new.a, new.b, new.c));
    

    This assumes that columns a, b and c are sufficient to uniquely identify the row. I’ve renamed the trigger and procedure to more accurately reflect what/when they are relevant; del is not all that appropriate as a prefix for something called on INSERT.

    CREATE PROCEDURE ins_table1(new_a INTEGER, new_b INTEGER, new_c INTEGER)
    
        DEFINE l_a LIKE table1.a;
    
        FOREACH SELECT a INTO l_a
                  FROM table1
                 WHERE a = new_a AND b = new_b AND c = new_c
           RAISE EXCEPTION -271, -100;
        END FOREACH;
    
    END PROCEDURE;
    

    This is called for each row that’s inserted. If the SELECT statement returns a row, it will enter the body of the FOREACH loop, so the exception will be raised and the INSERT will be aborted with a more or less appropriate error (-271 Could not insert new row into the table; -100 ISAM error: duplicate value for a record with unique key).

    If you try to do this validation with an AFTER trigger, you have to scan the entire table to see whether there are any duplicates, rather than just targeting the single key combination that was inserted. Note that in general, an INSERT can have multiple rows (think INSERT INTO Table SELECT * FROM SomeWhereElse). The performance difference will be dramatic! (Your query for an AFTER trigger would have to be something like SELECT a, b, c FROM table1 GROUP BY a, b, c HAVING COUNT(*) > 1.)

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

Sidebar

Related Questions

I need to perform the following task : There are two 'ul' elements containing
I have a jQuery function already to perform the task I need but is
Very simple question. I need to perform a task when the user closes his
I have a task to perform an HttpWebRequest using Task<WebResponse>.Factory.FromAsync(req.BeginGetRespone, req.EndGetResponse) which can obviously
Previously, I am using STL map to perform the mentioned task. struct ltstr {
I have a task I need to perform, do_stuff(opts) , that will take ~1s
I have two JavaScript code snippets. These perform specific task when an 'Update' button
In VIM, I need to perform a simple task - highlight ( and ).
I want to perform a task using Java at specific, given hour . My
jQuery.parseJSON and JSON.parse are two functions that perform the same task. If the jQuery

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.