473,779 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying data from one database to another

37 New Member
Hi

I am using the following code to copy data from one database table into another database table:

SELECT * INTO Products From exportdb.mdb.ex porttable

However the query simply deletes everything in the Products table before copying the content of the exporttable.

what is the syntax to run a similar query so that data is simply appended to the products table instead of deleting the entire contents before copying the exporttable?
Jan 20 '07 #1
5 17518
ADezii
8,834 Recognized Expert Expert
Hi

I am using the following code to copy data from one database table into another database table:

SELECT * INTO Products From exportdb.mdb.ex porttable

However the query simply deletes everything in the Products table before copying the content of the exporttable.

what is the syntax to run a similar query so that data is simply appended to the products table instead of deleting the entire contents before copying the exporttable?
If I understand you correctly, here is some code which will hopefully point you in the right direction. Let me know if this is what you were looking for:
Expand|Select|Wrap|Line Numbers
  1. 'The following code snippet will Import a Table from an
  2. 'External Database and append its Records to a Table in the current Database
  3. Dim MYtdf As TableDef
  4.  
  5. For Each MYtdf In CurrentDb.TableDefs
  6.   'DELETE Imported Table if it exists
  7.   If MYtdf.Name = "tblEmployeesAppend" Then
  8.     CurrentDb.TableDefs.Delete MYtdf.Name
  9.   End If
  10. Next
  11.  
  12. 'Import tblEmployees from C:\Test2\Test2.mdb and rename it tblEmployeesAppend
  13. DoCmd.TransferDatabase acImport, "Microsoft Access", "C:\Test2\Test2.mdb", acTable, "tblEmployees", "tblEmployeesAppend"
  14.  
  15. DoCmd.SetWarnings False     'Turn System Messages OFF
  16.   'Run Append Query adding all Records from tblEmployeesAppend to tblEmployees
  17.   DoCmd.OpenQuery "qryAppendToEmployee"
  18. DoCmd.SetWarnings True      'Turn System Messages ON
  19.  
  20. 'No need to keep it around
  21. CurrentDb.TableDefs.Delete "tblEmployeesAppend"
Jan 20 '07 #2
NeoPa
32,577 Recognized Expert Moderator MVP
I think the question should have been more like :
What is the correct SQL syntax to append data into a table rather than to create a table?
My existing query
Expand|Select|Wrap|Line Numbers
  1. SELECT * INTO Products From exportdb.mdb.exporttable
clears out the table prior to adding the new data :confused:

The syntax needed is INSERT INTO rather than SELECT INTO.
INSERT INTO Statement
Adds a record or multiple records to a table. This is referred to as an append query.

Syntax
Multiple-record append query:

INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabas e]
SELECT [source.]field1[, field2[, ...]
FROM tableexpression

Single-record append query:

INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])

The INSERT INTO statement has these parts:

Part Description
target The name of the table or query to append records to.
field1, field2 Names of the fields to append data to, if following a target argument, or the names of fields to obtain data from, if following a source argument.
externaldatabas e The path to an external database. For a description of the path, see the IN clause.
source The name of the table or query to copy records from.
tableexpression The name of the table or tables from which records are inserted. This argument can be a single table name or a compound resulting from an INNER JOIN, LEFT JOIN, or RIGHT JOIN operation or a saved query.
value1, value2 The values to insert into the specific fields of the new record. Each value is inserted into the field that corresponds to the value's position in the list: value1 is inserted into field1 of the new record, value2 into field2, and so on. You must separate values with a comma, and enclose text fields in quotation marks (' ').
Jan 22 '07 #3
ozzii
37 New Member
I think the question should have been more like :
What is the correct SQL syntax to append data into a table rather than to create a table?
My existing query
Expand|Select|Wrap|Line Numbers
  1. SELECT * INTO Products From exportdb.mdb.exporttable
clears out the table prior to adding the new data :confused:

The syntax needed is INSERT INTO rather than SELECT INTO.
Yes you are right. The SQL syntax I am after is append data. How would i run this query in ASP though?
Jan 22 '07 #4
ozzii
37 New Member
If I understand you correctly, here is some code which will hopefully point you in the right direction. Let me know if this is what you were looking for:
Expand|Select|Wrap|Line Numbers
  1. 'The following code snippet will Import a Table from an
  2. 'External Database and append its Records to a Table in the current Database
  3. Dim MYtdf As TableDef
  4.  
  5. For Each MYtdf In CurrentDb.TableDefs
  6.   'DELETE Imported Table if it exists
  7.   If MYtdf.Name = "tblEmployeesAppend" Then
  8.     CurrentDb.TableDefs.Delete MYtdf.Name
  9.   End If
  10. Next
  11.  
  12. 'Import tblEmployees from C:\Test2\Test2.mdb and rename it tblEmployeesAppend
  13. DoCmd.TransferDatabase acImport, "Microsoft Access", "C:\Test2\Test2.mdb", acTable, "tblEmployees", "tblEmployeesAppend"
  14.  
  15. DoCmd.SetWarnings False     'Turn System Messages OFF
  16.   'Run Append Query adding all Records from tblEmployeesAppend to tblEmployees
  17.   DoCmd.OpenQuery "qryAppendToEmployee"
  18. DoCmd.SetWarnings True      'Turn System Messages ON
  19.  
  20. 'No need to keep it around
  21. CurrentDb.TableDefs.Delete "tblEmployeesAppend"
The above code does look similar to what i am trying to do. However I am trying to run this query with ASP. Basically I have a production database (Access) running on a web server, and a duplicate "staging" database which is to be used for table import to the production database. For example, I make changes to the table in my local copy of the database, then FTP it to the web server to become the "staging" database. I now need to be able to import the data from this table from the staging database to the production database using ADO (VBScript). The SQL query needs to be an append action. Is there a simple way to do this, given the source and destination tables will have separate connections?
Jan 22 '07 #5
NeoPa
32,577 Recognized Expert Moderator MVP
I think the question should have been more like :
What is the correct SQL syntax to append data into a table rather than to create a table?
My existing query
Expand|Select|Wrap|Line Numbers
  1. SELECT * INTO Products From exportdb.mdb.exporttable
clears out the table prior to adding the new data :confused:

The syntax needed is INSERT INTO rather than SELECT INTO.
Yes you are right. The SQL syntax I am after is append data. How would I run this query in ASP though?
I'm afraid I know little or nothing about ASP.
I would suggest taking this to the ASP forum for more expert help on ASP, now you have the SQL syntax you need.
Jan 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2668
by: Jason | last post by:
In enterprise manager I am copying a table from one database to another. I am using the dts wizard to import the data. After I successfully import the data, I open both tables to compare the records to make sure they are the same. I right click on a field and click "last" for both tables. However, the record is different for both. If I do a query the record is still there but they do not show up in the same order. Why does'nt the...
1
8690
by: Jani Tamminen | last post by:
I want to copy data from our production database to the development database. I want to move only the data. I do not need the table structure, constrains or anything else. I think I can use the db2move command to export out all the data like the following: db2move dbname export -tc schema1
5
3513
by: Lyn | last post by:
I am trying to copy selected fields from one table to another, by reading the source table record into a recordset (ADO) and then copying the relevant fields to an SQL statement "INSERT INTO...". The numeric and text fields copy without a problem, but it all falls in a heap when I try to copy a picture object field (data type OLE Object in both tables). I seem to be missing something ??? Reduced to its simplest form, this is the code...
5
2354
by: TB | last post by:
Hi All: This news group is proving to be great help on my path towards mastering ASP.NET thanks to all of you helpful souls out there. I am looking forward to the day when I can contribute with a few ounces of hard-won knowledge as well. Meanwhile I have this (hopefully small) problem.
4
15423
by: zMisc | last post by:
Is it possible to copy a table from one schema to another schema by just copying the frm file to the directory for the new schema? What is the best way to create a new database with all the tables in it automatically? I was hoping to have the tables (the frm files) included in a subdirectory and when required, just create a new schema then copy all the frm files into it.
3
1532
by: John | last post by:
Hi all, My application updates a sql server 2005 express database prior to copying it with the result being the "in use by another process" and I cannot copy it as a result. I've posted the code that updates the database below. Please could someone let me know how I free up the mdf file properly prior to copying it. Otherwise, does someone know how I can free it up programmatically or simply copy it without receiving the errror?
0
1565
by: berwiki | last post by:
I am trying to copy a table to another SQL 2000 Database, but I continually get errors. When I right-click, choose All-Tasks, Export-Data and go through the DTS settings, I get an 'Unspecified Error' on row 107 (which, looking at all visible data, there appears to be no difference than the 100 rows before it). Failed: Copying to a different database. Failed: Copying to the Same database with a different table name.
6
4578
by: Ryan | last post by:
I have 2 Access '97 databases. I am trying to migrate all the data from one to the other (append to existing records). I do not have Access '97 and opening with Access XP or later causes problems. I have found I can connect to the databases in Visual Studio 2005 and insert records, etc, so I'm trying to write my code using VB 2005. I have 2 connections, 2 datasets... OldDS and NewDS. First I populate both datasets:...
5
1897
by: mark_aok | last post by:
Hi all, I have a situation where I have a split database. At the back end, I need to - create a new table (I will call it newTable) with the exact fields, and relationships as another table (let's call it oldTable, and I need to copy everything EXCEPT the data). - Then I need to delete oldTable, and rename newTable 'oldTable'
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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...
1
10074
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
9930
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
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
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
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
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.