473,466 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inserting Duplicate Data

This is probably a silly question to most of you, but I'm in the process
of splitting off years from a large DB to several smaller ones. Some of
the existing smaller DBs already have most of the data for their
respective years. But some of the same data is also on the source DB.

If I simply do an insert keying on the year column, and a row being
inserted from the source DB already exists in the target DB, will a
duplicate row be created?

And if so, how can I avoid that?

Thanks,
John Steen

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 6072
On 01 Oct 2003 18:51:51 GMT, John Steen <mo********@hotmail.com>
wrote:
This is probably a silly question to most of you, but I'm in the process
of splitting off years from a large DB to several smaller ones. Some of
the existing smaller DBs already have most of the data for their
respective years. But some of the same data is also on the source DB.

If I simply do an insert keying on the year column, and a row being
inserted from the source DB already exists in the target DB, will a
duplicate row be created?

And if so, how can I avoid that?

Thanks,
John Steen

*** Sent via Developersdex http://www.developersdex.com *** It depends what constraints exist on the inserted table. If for
example there is a unique key then you will not be able to insert a
row with the same key. Unfortunately a simple insert will not just
insert the rows that are not duplicates, the whole insert will fail.

If there are no constraints then duplicates will be created.

One approach would be to insert all the rows to a temporary table.
Then delete the rows that exist in the second table and finally insert
all the remaining rows from temp to table two. This gives you a half
way stage to check your work.

Otherwise you simply put an AND clause on your initial select that
excludes rows that would be duplicated. You need to understand the
data in order to be able to identify what constitutes a duplicate.

I don't think there's much more to say without knowing the tables and
the data.Don't just participate in USENET...get rewarded for it!


Jul 20 '05 #2
John Steen (mo********@hotmail.com) writes:
If I simply do an insert keying on the year column, and a row being
inserted from the source DB already exists in the target DB, will a
duplicate row be created?
Not if the database is properly set up with a primary key constraint.
And if so, how can I avoid that?


Whatever, you need to do something like:

INSERT tbl (....)
SELECT ...
FROM src
WHERE NOT EXISTS (SELECT *
FROM tbl
WHERE tbl.keycol = src.keycol)

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Charles | last post by:
Hi MS Access & MS SQL Server Gurus ! I am trying to delete duplicate data from a LINKED SQL Server 2000 table (LinkedTable) and insert the result into a local (in Access) table. The following...
3
by: craig.brenizer | last post by:
I have a table of data that has duplicate values in the pagenumber field. How can I combine the data so that the page numbers of duplicate part numbers are on one record for that part number? ...
0
by: tom | last post by:
Hi, I have a datagrid which display the data like this: bookName Author ------------------ book1 Bob book1 Nancy book2 Tim ------------------
2
by: Mike Charney | last post by:
I have a temp table that has data I am inserting into a SQL DB table. There is a column in both tables called PAT_ID. I need to check the SQL table against the temp table for duplicate data in...
1
by: anjanareddy | last post by:
Hai, i am unable to inserting duplicate data into UNIQUE index column, Is there any other process, to insert duplicate data into UNIQUE index column? plz let me know.. Thanks & Regards...
1
by: oaklander | last post by:
I would like to make sure there are no duplicate data entries in my Oracle 9i table (called MainTable) which has an Id field that is the primary key, ValData with a varchar data type, Fid and Fid2...
0
by: srinivasaraonagisetty | last post by:
hi, I am faceing one problem, while inserting the data in db2 using clob. actually i am writing this type code: public class DBParam { private InputStream inputstream; private static int...
3
by: killswitch101 | last post by:
I need to get all of the non-duplicate data out of 2 tables (ci and hi) i can't seem to work it out i think i need to use the minus command but that will only display the data for 1 table can...
1
by: AccessBeetle | last post by:
I am working with SQL server 2005 backend and Access 2003 frond end. I have a form bound to a table tblReportDetails. There are several(5) tabs on the same form. Each tab has its own subform. Every...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.