473,805 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
+ 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 6090
On 01 Oct 2003 18:51:51 GMT, John Steen <mo********@hot mail.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********@hot mail.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
2382
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 code works in SQL Server 2000 but NOT in Access, could any one tell me what's wrong with it? SELECT a.id, a.change_id AS chgid, a.Action_desc as Actiondescr INTO
3
5645
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? Here is what "table1" looks like now. Note that partnumbers 10-20 and 20-62 duplicate data, except for the pagenumbers, which are different. partnumber price pagenumber
0
1188
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
1760
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 both columns of both tables. In other words if one row in the temp table PAT_ID has a value of 472440 and the SQL DB table also has a row with PAT_ID = 472440 then I want to delete the temp table row.
1
2266
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
1733
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 are number data types. Id ValData Fid Fid2 1 abc 34 2 2 efg 23 34 3 zeo 25 43 Sometimes someone can enter a duplicate ValData, Fid and Fid2 and it will end up like this:
0
2922
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 htmLength=0; public DBParam(String c,String k) //k has the data of html { this.inputStream=getStreams(k); this.htmlLength=k.length();
3
1529
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 anyone help
1
1718
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 other subform works fine but the very first tab has a subform which shows three cascading comboboxex, cmbCounty, cmbTownship, cmbQuad. cmbTownship and cmbQuad shows values based on the county selected in cmbCounty. One record from the main form can...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.