Home All Groups Group Topic Archive Search About

Insert Duplicate row in Temp Table



Author
16 Mar 2007 8:54 AM
shantanu
Hi all
          My requirement is like I need to write a trigger which will
compare the data with the existing one in the table and if the data is
duplicate then insert the data into a temp table.

Can anybody help me with the query
thanks
shantanu

Author
16 Mar 2007 9:22 AM
Paul Ibison
Can you post up the schema of the table and explain what is meant by
duplicate - ie all fields identical, just key values identical etc. Also,
it's unclear if the duplicate record is still to be added to the main table
as well as the temp table - please clarify as this will determine what type
of trigger you need (instead of versus after). Finally, when you say temp
table I assume you don't mean a table starting with '#' and a 'real' table -
can you tell me the table name and schema. Once we have all this info
someone'll be able to craft the trigger for you.
Cheers,
             Paul Ibison SQL Server MVP, www.replicationanswers.com
Are all your drivers up to date? click for free checkup

Author
16 Mar 2007 9:43 AM
shantanu
On Mar 16, 2:22 pm, "Paul Ibison" <Paul.Ibi***@Pygmalion.Com> wrote:
> Can you post up the schema of the table and explain what is meant by
> duplicate - ie all fields identical, just key values identical etc. Also,
> it's unclear if the duplicate record is still to be added to the main table
> as well as the temp table - please clarify as this will determine what type
> of trigger you need (instead of versus after). Finally, when you say temp
> table I assume you don't mean a table starting with '#' and a 'real' table -
> can you tell me the table name and schema. Once we have all this info
> someone'll be able to craft the trigger for you.
> Cheers,
>              Paul Ibison SQL Server MVP,www.replicationanswers.com

thanx for the reply Paul

the table schema is like
PROJ_ID    int    4    1
ASSN_UID    int    4    1
AB_REF_ENT_PROJ_ID    int    4    1
AB_BASE_NUM    smallint    2    1
AB_BASE_START    datetime    8    1
AB_BASE_FINISH    datetime    8    1
AB_BASE_WORK    decimal    13    1
AB_BASE_COST    decimal    13    1
AB_BASE_COST_PER_USE    decimal    13    1


where Projid is the primary key
My question was that i need to create a BEFORE INSERT Trigger that
will check if the data to be inserted is already present in the table.
Now if the data is present then the trigger will run a insert query to
save that duplicate data into a XYZ table.
I hope now it will  be clear

thanx again
shantanu
Author
16 Mar 2007 10:51 AM
Paul Ibison
Hi Shantanu,
still need to know how you define that the data is already present - any
particular field, or is a duplicate defined as all fields identical.
Also need the name of the audit table.
Cheers,
             Paul Ibison SQL Server MVP, www.replicationanswers.com

Bookmark and Share