|
Pervasive.SQL provides an ODBC interface, which makes it easy to access your data from a large number of third-party programs. Sometimes data must be made available in other ways or in specific formats. To ease the migration of data to and from Pervasive.SQL databases, Pervasive Control Center (PCC) includes import and export wizards.
The Import/Export wizards in PCC support two different data formats, which can be read and written. The formats are shown in Table 3-5.
An empty string is designated in exported format by double quotes. A column defined as nullable and that contains a NULL is designated in exported format by two commas (two field separators) together.
This section describes the procedures used to export or import data from or to Pervasive.SQL.
To export data from a Pervasive.SQL database table

This example exports comma delimited records.
Select the box marked Write column names at first row if you would like the Export Wizard to create a header row at the beginning of the file that includes the name of each column from the DDF. This would be particularly useful if you are exporting to another application, such as Excel, so that the contents will be identified.



Tip
If the export fails because of invalid data, you can troubleshoot the record that contains the invalid data. Click Abort on the error message, then No on the message that asks if you want to delete the partially exported file. Open the partially exported file in an editor. The last record in the file is the record containing the invalid data.

To import data into an existing table
You designate an empty string by using double quotes. You designate a NULL by using two commas (two field separators) together. For example, the following table shows how you would designate a "middle initial" as an empty string and as a NULL, respectively.

Select the box marked Column names at first row if you selected the option Write column names at first row when exported the file (Figure 3-24).
Click Next when done.


You cannot import fewer fields than exist in the table or in the import file. Both the import file and the table must have the same number of columns. The only factor you can control with the INSERT statement is how the import file columns correspond to the table columns.
The first named column receives the data from the first column in the import file, the second named column receives the data from the second column in the import file, and so on.
For example, if you want the data in the first column of the import file to go into the third column of your table, you must put the name of the third column first in the column list.

To stop the import, click Cancel, or else click Import.

To import specific columns of an SDF file into a table using the import wizard
In some cases you may wish to import only some of the columns in a table into a new table. Using an example, this procedure explains how to do it.
CREATE TABLE Customer (FirstName char(10), LastName char(10), Telephone char(12), AmtOwed currency)Next, assume that the following statements were executed to insert sample data:
INSERT INTO Customer VALUES ('Alexi', 'Pruneda', '512-264-9999', 1200.69) INSERT INTO Customer VALUES ('Matte', 'Pruneda', '512-264-9999', 9999.69)
CREATE TABLE phonelist (FirstName char(10), LastName char(10), Telephone char(12))Notice that this table does not have all the columns of the original one.
cust.sdf:SELECT * FROM CustomerNote that the export file contains four columns:
"Alexi","Pruneda","512-264-9999","1200.69" "Matt","Pruneda","512-264-9999","9999.69"
CUST.SDF file. The named fields do not need to be in the same order as they exist in your destination table. You can move the column names in the INSERT statement around as necessary to correspond properly with the fields in the SDF file. Click Next.
The import process can exclude any number of fields at the end of each record, but it cannot exclude any fields at the beginning or middle of a record. As in the example above, the SDF file contained 4 fields, but we imported only the first 3 by including only 3 question marks in the VALUES clause. You may not exclude beginning or middle values from the SDF file, as in VALUES ( ,?,?,?) or VALUES(?, ,?,?). These syntax forms generate error messages. If you need to achieve this effect, then you should use a SELECT statement during your export process to generate an SDF file that contains only the columns you want to import into your other table.
The process is simpler if you are exporting and importing the same number of fields to and from the SDF (standard data format) files. Then the SQL queries are not necessary, and you can choose to export and import the full table.
If the export and import tables are part of the same database, importing can also be done using SQL queries. The following example would achieve the same results as the steps listed above:
|
Chapter contents
Prev topic: Viewing and Modifying Data
|