Data | database | Conversion here, a summary of the transformation of the SQLSERVER,DBF two forms is made.
One: From the dBASE file, import data into the SQL database, very simple, directly using the following statement:
/*===================================================================*/
--If the table that accepts the data import already exists
INSERT INTO table SELECT * FROM
OpenRowset (' MICROSOFT. JET. oledb.4.0 '
, ' DBase 5.0;database=c:\ ', ' select * from [TEST.DBF] '
--If you import data and generate a table
SELECT * Into table from
OpenRowset (' MICROSOFT. JET. oledb.4.0 '
, ' DBase 5.0;database=c:\ ', ' select * from [TEST.DBF] '
/*===================================================================*/
-If you export data to dBASE from a SQL database, if the dBASE file already exists, you can simply use:
INSERT INTO
OpenRowset (' MICROSOFT. JET. oledb.4.0 '
, ' DBase 5.0;database=c:\ ', ' select * from [TEST.DBF] '
SELECT * FROM table
/*--Description:
Database=c:\ C:\ is the storage directory of DBF files
' SELECT * from [TEST.DBF] test.dbf refers to the DBF filename
--*/
If the dBASE file does not exist, you need to use the following stored procedure.
/*--Data export dbase
Export the data from the table to dBASE, and if the file does not exist, the file will be created automatically
Only export standard data types are supported based on commonality considerations
--*/
/*--Call Example
--Export dBASE
P_EXPORTTB @tbname = ' Area information ', @path = ' C:\ ', @over =0
--*/
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ P_EXPORTTB] and OBJECTPROPERTY (ID, N ' isprocedure ') = 1)
drop procedure [dbo]. [P_EXPORTTB]
Go
Create proc P_EXPORTTB
@tbname sysname--Name of the table to be exported
@path nvarchar (1000),--File storage directory
@fname nvarchar (250) = ',--filename, default to table name
@over bit=0-Overwrite files that already exist, append directly if not overridden
As
declare @err int, @src nvarchar (255), @desc nvarchar (255), @out int
declare @obj int, @constr nvarchar (1000), @sql varchar (8000), @fdlist varchar (8000)
--Parameter detection
If IsNull (@fname, ') = ' Set @fname = @tbname + '. dbf '
--Check if the file already exists
If Right (@path, 1) <> ' Set @path = @path + ' \ '
CREATE TABLE #tb (a bit,b bit,c bit)
Set @sql = @path + @fname
INSERT into #tb exec master. Xp_fileexist @sql
if exists (select 1 from #tb where a=1)
If @over =1
Begin
Set @sql = ' del ' + @sql
EXEC master.. xp_cmdshell @sql, No_output
End
Else
Set @over =0
Else
Set @over =1
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.