|
sql
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Insert Duplicate row in Temp Table
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 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 On Mar 16, 2:22 pm, "Paul Ibison" <Paul.Ibi***@Pygmalion.Com> wrote: thanx for the reply Paul> 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 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 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
Other interesting topics
Large database - unable to delete even 10 rows?
Deferred Name Resolution gone wild. SQL Server Backup and Transactions How to avoid creating duplicate indexes on the same column SQL Server 2005 compact edition with VB Table size Restore Failure OS Related ? ISNULL not working DATABASE Mail Account Setup Error SQLH2 |
|||||||||||||||||||||||