MySQL中的LOAD DATA INFILE错误

时间:2016-06-29 03:51:22

标签: sql-server import

我尝试将csv数据导入mySQL(Windows 7上的microsoft slq server 2014)。我使用以下代码

USE [DataAnalytics]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

DROP TABLE [dbo].[npi_yy]

CREATE TABLE [dbo].[npi_yy](

[NPI] [NUMERIC] (10) NULL,
[Entity Type Code] [NUMERIC] (1) NULL,
[Replacement NPI] [NUMERIC] (10) NULL,
[Employer Identification Number (EIN)] [VARCHAR] (9) NULL,
[Provider Organization Name (Legal Business Name)] [VARCHAR] (70) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING ON
GO

LOAD DATA INFILE 

    'c:\data\npidata_20050523-20160612_sample2.csv'

INTO TABLE [dbo].[npi_yy]

  FIELDS TERMINATED BY ',' ENCLOSED BY '"'

  LINES TERMINATED BY '\r\n'

  IGNORE 1 LINES;

出了错误:

Msg 102, Level 15, State 1, Line 354
Incorrect syntax near 'INFILE'.

我通过查看空表来检查CREATE TABLE是否正常工作。 并通过将文件名放在explore

中打开它来检查c:\data\npidata_20050523-20160612_sample2.csv是否存在

csv的负责人:

"NPI","Entity Type Code","Replacement NPI","Employer Identification Number (EIN)","Provider Organization Name (Legal Business Name)"
"1588667638","1","","",""
"1497758544","2","","<UNAVAIL>","CUMBERLAND COUNTY HOSPITAL SYSTEM
"1306849450","1","","",""
"1215930367","1","","",""
"1023011178","2","","<UNAVAIL>","NAPA VALLEY HOSPICE & ADULT DAY SERVICES"

有人知道出了什么问题吗?任何帮助都表示赞赏。

1 个答案:

答案 0 :(得分:2)

LOAD DATA语句外,您发布的代码均为Microsoft SQL ServerLOAD DATA是特定于MySQL的声明。它们是两个不相关的数据库软件,具有不同的语法规则,并以不同的方式扩展了SQL标准。他们不能混在一起。

LOAD DATA语句是MySQL提供的标准的扩展。 Microsoft SQL Server为此提供了BULK INSERT语句。

您的代码应该是:

BULK INSERT [dbo].[npi_yy]
FROM 'c:\data\npidata_20050523-20160612_sample2.csv'
WITH (
    FIELDTERMINATOR = ',',
    FIRSTROW = 2,
    ROWTERMINATOR = '\r\n'
)
GO

详细了解BULK INSERT声明。