KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Archiving Data to an External Database using SQL Export
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: August 9, 2011

This Tech Tip describes a technique to copy data from the internal 4D database to an External Database. In particular this technique leverages two powerful features in 4D v12:



Note that this technique assumes the internal and external table have the same structure. In other words the goal of such a technique would be to "archive" the internal data to an External Database. The internal data could later be deleted.

An overview of the process is as follows:



Here is a simple example:

// Export internal data.
ALL RECORDS([Table_1])
SQL EXPORT SELECTION([Table_1];$exportPath_t)

// Open External Database.
Begin SQL
   USE DATABASE DATAFILE :$externalDBPath_t;
End SQL

// The import script is called "Export.sql" and it's
// created in a folder called "SQLExport"

$importScript_t:=$exportPath_t+Folder separator+"SQLExport"\
   +Folder separator+"Export.sql"

// Import the data.
SQL EXECUTE SCRIPT($importScript_t;SQL On error abort)

// Don't forget to switch back to the internal database if needed.
Begin SQL
   USE DATABASE SQL_INTERNAL;
End SQL

See Also: