Foxpro dbf import SQL Server table

Source: Internet
Author: User
Tags dbase

---------- DBF import SQL Server table ----------

The following uses SQL2000, VFP6, and above as an example.

Method 1: execute the following statement in the query analyzer (select the corresponding database first)

-- If the SQL table that accepts the imported data already exists
Select * from openrowset ('msdasql ', 'driver = Microsoft Visual FoxPro Driver; SourceType = DBF; SourceDB = c :\', 'select * from aa. dbf ')

-- You can also import the corresponding column name, for example:
Insert into an existing SQL table name (column name 1, column name 2 ...) select (corresponding to column 1, corresponding to column 2 ...) from openrowset ('msdasql ', 'driver = Microsoft Visual FoxPro Driver; SourceType = DBF; SourceDB = c: \', 'select * from aa. dbf ')

-- If the SQL table that accepts the imported data does not exist, create

-- Method 1:
Select * Into the SQL table name to be generated from OpenRowSet ('Microsoft. jet. oledb.4.0 ', 'dbase IV; HDR = no; IMEX = 2; database = c: \', 'select * From DBF table name. dbf ')

-- Method 2:
Select * Into the SQL table name to be generated from OpenRowSet ('Microsoft. jet. oledb.4.0 ', 'dbase III; HDR = no; IMEX = 2; database = c: \', 'select * From DBF table name. dbf ')

-- Method 3:
Select * Into the SQL table name to be generated from OpenRowSet ('msdasql ', 'driver = Microsoft Visual FoxPro driver; sourcetype = DBF; sourcedb = c :\', 'select * From DBF table name. dbf ')

-- After the SQL Server is imported using the first two methods, if the source table is opened with VFP, the system does not prompt "file cannot be accessed". After the statement is executed, the source table is disabled. However, it is not satisfactory that the SQL table fields in the source table are converted to nvarchar after being imported using the first two methods.

-- The third method has one drawback: After importing the DBF table into SQL Server, you can use VISUAL FOXPRO to open the DBF table immediately and the system will prompt "file access unavailable ", that is, the table is still opened by SQL. However, after about one minute, you can open the DBF table, indicating that the analyzer will shut down the table after a period of time.

-- You can export only a few fields.
Select * into the SQL table name to be generated from openrowset ('msdasql ', 'driver = Microsoft Visual FoxPro Driver; SourceType = DBF; SourceDB = c: \', 'select Field 1, field 2 from aa. dbf ')

/* -- Description:
SourceDB = c: \ is the directory where dbf Files are stored.
Aa. DBF is the name of the dbf file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.