472,785 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,785 software developers and data experts.

Copying data from one database to another

37
Hi

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

SELECT * INTO Products From exportdb.mdb.exporttable

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 17191
ADezii
8,834 Expert 8TB
Hi

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

SELECT * INTO Products From exportdb.mdb.exporttable

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,534 Expert Mod 16PB
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 externaldatabase]
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.
externaldatabase 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
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
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,534 Expert Mod 16PB
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
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...
1
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...
5
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...". ...
5
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...
4
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...
3
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...
0
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...
6
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...
5
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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.