2010-08-30 55 views
0

我是第一次使用BCP用戶。我有一個XML文件,我需要導入SQL Server中的新表。這是使用SQL Server 2008和BCP版本10.50.16。我通讀了文檔,但我得到了37萬錯誤! (這是一個非常大的文件)。當我打開錯誤日誌時,我只看到一堆問號。正確的BCP語法

關於此XML文件:它確實使用了新行來描述行,但是,它使用空格字符來分隔字段。所以我不確定那是否導致它失敗。失敗消息是:

BCP copy in failedI希望它更具描述性。有沒有辦法獲得更詳細的錯誤信息?

否則,這裏是我的命令:

d:\SQL Tables\data>bcp Development.dbo.wbl_zSkywardEnrollment2 in zSkywardEnroll 
ment.xml -fSE_format.fmt -m50 -eseErrorLog -b100 -t0x20 -T -F107 

所有這些文件均在同一目錄下。我知道它說要指定完整的文件路徑,但因爲它們都在同一個目錄中,我還看到了另一個他們沒有指定目錄的例子,我認爲這足夠了。

我已經試過這個沒有格式文件也做,它交互做,但得到相同的錯誤。

這是我的格式文件:

10.0 
32 
1  SQLINT    0  4  " " 1  SCHOOL_YEAR        "" 
2  SQLNCHAR   2  20  " " 2  ENTITY_ID         SQL_Latin1_General_CP1_CI_AS 
3  SQLINT    0  4  " " 3  TERM_NBR         "" 
4  SQLINT    1  4  " " 4  SCHD_HST_GRAD_YEAR       "" 
5  SQLNCHAR   2  60  " " 5  OTHER_ID         SQL_Latin1_General_CP1_CI_AS 
6  SQLNUMERIC   1  19  " " 6  GRAD_YR         "" 
7  SQLNCHAR   2  120  " " 7  LAST_NAME         SQL_Latin1_General_CP1_CI_AS 
8  SQLNCHAR   2  60  " " 8  FIRST_NAME         SQL_Latin1_General_CP1_CI_AS 
9  SQLNCHAR   2  60  " " 9  MIDDLE_NAME        SQL_Latin1_General_CP1_CI_AS 
10  SQLDATETIME   1  8  " " 10 BIRTHDATE         "" 
11  SQLNCHAR   2  4  " " 11 GENDER          SQL_Latin1_General_CP1_CI_AS 
12  SQLNCHAR   2  20  " " 12 RACE_CODE         SQL_Latin1_General_CP1_CI_AS 
13  SQLNCHAR   2  40  " " 13 DISTRICT_CODE        SQL_Latin1_General_CP1_CI_AS 
14  SQLBIT    1  1  " " 14 X_SPECIAL_EDUCATION      "" 
15  SQLBIT    1  1  " " 15 X_GIFTED_TALENTED       "" 
16  SQLBIT    1  1  " " 16 X_SECTION_504        "" 
17  SQLBIT    1  1  " " 17 X_MIGRANT         "" 
18  SQLBIT    1  1  " " 18 X_IEP          "" 
19  SQLBIT    1  1  " " 19 X_IEP_ACCOM        "" 
20  SQLBIT    1  1  " " 20 X_ESL          "" 
21  SQLNCHAR   2  4  " " 21 STUDENT_STATUS        SQL_Latin1_General_CP1_CI_AS 
22  SQLINT    0  4  " " 22 STUDENT_ID         "" 
23  SQLINT    1  4  " " 23 ENG_PROF         "" 
24  SQLNCHAR   2  60  " " 24 ALPHAKEY         SQL_Latin1_General_CP1_CI_AS 
25  SQLNCHAR   2  20  " " 25 SCHOOL_ID         SQL_Latin1_General_CP1_CI_AS 
26  SQLNUMERIC   1  19  " " 26 MN_EDE_NBR         "" 
27  SQLNCHAR   2  20  " " 27 LANGUAGE_CODE        SQL_Latin1_General_CP1_CI_AS 
28  SQLINT    1  4  " " 28 ADVISOR         "" 
29  SQLBIT    1  1  " " 29 MN_LIMITED_ENGLISH       "" 
30  SQLNCHAR   2  20  " " 30 TYPE_STUDENT_ID       SQL_Latin1_General_CP1_CI_AS 
31  SQLNCHAR   2  20  " " 31 CY_TEAM_SCHD_ID       SQL_Latin1_General_CP1_CI_AS 
32  SQLNCHAR   2  20  " " 32 HOMEROOM_NUMBER       SQL_Latin1_General_CP1_CI_AS 

這是我的SQL表:

CREATE TABLE [dbo].[wbl_zSkywardEnrollment2](
    [SCHOOL_YEAR] [int] NOT NULL, 
    [ENTITY_ID] [nvarchar](10) NOT NULL, 
    [TERM_NBR] [int] NOT NULL, 
    [SCHD_HST_GRAD_YEAR] [int] NULL, 
    [OTHER_ID] [nvarchar](30) NULL, 
    [GRAD_YR] numeric(19,0) NULL, 
    [LAST_NAME] [nvarchar](60) NOT NULL, 
    [FIRST_NAME] [nvarchar](30) NULL, 
    [MIDDLE_NAME] [nvarchar](30) NULL, 
    [BIRTHDATE] datetime NULL, 
    [GENDER] [nvarchar](2) NULL, 
    [RACE_CODE] [nvarchar](10) NULL, 
    [DISTRICT_CODE] [nvarchar](20) NULL, 
    [X_SPECIAL_EDUCATION] bit NULL, 
    [X_GIFTED_TALENTED] bit NULL, 
    [X_SECTION_504] bit NULL, 
    [X_MIGRANT] bit NULL, 
    [X_IEP] bit NULL, 
    [X_IEP_ACCOM] bit NULL, 
    [X_ESL] bit NULL, 
    [STUDENT_STATUS] [nvarchar](2) NULL, 
    [STUDENT_ID] [int] NOT NULL, 
    [ENG_PROF] [int] NULL, 
    [ALPHAKEY] [nvarchar](30) NOT NULL, 
    [SCHOOL_ID] [nvarchar](10) NULL, 
    [MN_EDE_NBR] [numeric](19, 0) NULL, 
    [LANGUAGE_CODE] [nvarchar](10) NULL, 
    [ADVISOR] [int] NULL, 
    [MN_LIMITED_ENGLISH] bit NULL, 
    [TYPE_STUDENT_ID] [nvarchar](10) NULL, 
    [CY_TEAM_SCHD_ID] [nvarchar](10) NULL, 
    [HOMEROOM_NUMBER] [nvarchar](10) NOT NULL 
) ON [PRIMARY] 

而且我也試圖與第1行開始我很好奇這行應該BCP開始?此XML的第1行以Schema和ElementType信息開始。但是第107行是rs:數據部分的起點。

這個XML文件的第一部分:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' 

    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' 

    xmlns:rs='urn:schemas-microsoft-com:rowset' 

    xmlns:z='#RowsetSchema'> 

<s:Schema id='RowsetSchema'> 

    <s:ElementType name='row' content='eltOnly'> 

     <s:AttributeType name='c0' rs:name='SCHOOL_YEAR' rs:number='1'> 

      <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:AttributeType name='c1' rs:name='ENTITY_ID' rs:number='2'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='10' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:AttributeType name='c2' rs:name='TERM_NBR' rs:number='3'> 

      <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:AttributeType name='c3' rs:name='SCHD_HST_GRAD_YEAR' rs:number='4' rs:nullable='true'> 

      <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c4' rs:name='OTHER_ID' rs:number='5' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='24'/> 

     </s:AttributeType> 

     <s:AttributeType name='c5' rs:name='GRAD_YR' rs:number='6' rs:nullable='true'> 

      <s:datatype dt:type='number' rs:dbtype='numeric' dt:maxLength='19' rs:scale='0' rs:precision='15' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c6' rs:name='LAST_NAME' rs:number='7'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='60' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:AttributeType name='c7' rs:name='FIRST_NAME' rs:number='8' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='30'/> 

     </s:AttributeType> 

     <s:AttributeType name='c8' rs:name='MIDDLE_NAME' rs:number='9' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='30'/> 

     </s:AttributeType> 

     <s:AttributeType name='BIRTHDATE' rs:name='BIRTHDATE' rs:number='10' rs:nullable='true' rs:write='true'> 

      <s:datatype dt:type='date' dt:maxLength='6' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='GENDER' rs:name='GENDER' rs:number='11' rs:nullable='true' rs:write='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='2'/> 

     </s:AttributeType> 

     <s:AttributeType name='c11' rs:name='RACE_CODE' rs:number='12' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/> 

     </s:AttributeType> 

     <s:AttributeType name='c12' rs:name='DISTRICT_CODE' rs:number='13' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='14'/> 

     </s:AttributeType> 

     <s:AttributeType name='c13' rs:name='X_SPECIAL_EDUCATION' rs:number='14' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c14' rs:name='X_GIFTED_TALENTED' rs:number='15' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c15' rs:name='X_SECTION_504' rs:number='16' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c16' rs:name='X_MIGRANT' rs:number='17' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c17' rs:name='X_IEP' rs:number='18' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c18' rs:name='X_IEP_ACCOM' rs:number='19' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c19' rs:name='X_ESL' rs:number='20' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c20' rs:name='STUDENT_STATUS' rs:number='21' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='2'/> 

     </s:AttributeType> 

     <s:AttributeType name='c21' rs:name='STUDENT_ID' rs:number='22'> 

      <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:AttributeType name='c22' rs:name='ENGL_PROF' rs:number='23' rs:nullable='true'> 

      <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='ALPHAKEY' rs:name='ALPHAKEY' rs:number='24' rs:write='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='22' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:AttributeType name='c24' rs:name='SCHOOL_ID' rs:number='25'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='10' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:AttributeType name='c25' rs:name='MN_EDE_NBR' rs:number='26' rs:nullable='true'> 

      <s:datatype dt:type='number' rs:dbtype='numeric' dt:maxLength='19' rs:scale='0' rs:precision='15' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c26' rs:name='LANGUAGE_CODE' rs:number='27' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/> 

     </s:AttributeType> 

     <s:AttributeType name='c27' rs:name='ADVISOR' rs:number='28' rs:nullable='true' rs:write='true'> 

      <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c28' rs:name='MN_LIMITED_ENGLISH' rs:number='29' rs:nullable='true'> 

      <s:datatype dt:type='boolean' dt:maxLength='2' rs:fixedlength='true'/> 

     </s:AttributeType> 

     <s:AttributeType name='c29' rs:name='TYPE_STUDENT_ID' rs:number='30' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/> 

     </s:AttributeType> 

     <s:AttributeType name='c30' rs:name='CY_TEAM_SCHD_ID' rs:number='31' rs:nullable='true'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='6'/> 

     </s:AttributeType> 

     <s:AttributeType name='c31' rs:name='HOMEROOM_NUMBER' rs:number='32'> 

      <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='10' rs:maybenull='false'/> 

     </s:AttributeType> 

     <s:extends type='rs:rowbase'/> 

    </s:ElementType> 

</s:Schema> 

<rs:data> 

    <z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01' 

     GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False' 

     c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False' 

     c29='R' c30='' c31=''/> 

    <z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01' 

     GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False' 

     c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False' 

     c29='R' c30='' c31=''/> 

    <z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01' 

     GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False' 

     c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False' 

     c29='R' c30='' c31=''/> 

    <z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01' 

     GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False' 

     c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False' 

     c29='R' c30='' c31=''/> 

    <z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01' 

     GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False' 

     c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False' 

     c29='R' c30='' c31=''/> 

    <z:row c0='2004' c1='057' c2='0' c3='2010' c4='671590' c5='2010' c6='AANENSON' c7='SHELLI' c8='A' BIRTHDATE='1992-07-01' 

     GENDER='F' c11='5' c12='' c13='False' c14='True' c15='False' c16='False' c17='False' c18='False' c19='False' 

     c20='I' c21='12' c22='7' ALPHAKEY='AANENSHE000' c24='057' c25='624000671590' c26='011' ADVISOR='0' c28='False' 

     c29='R' c30='' c31=''/> 
+0

我會誠實地嘗試使用SSIS來讀取XML數據。 BCP非常「黑匣子」 - 你可以將數據輸入,數據輸出出來,而且對工作的原因和方式幾乎沒有任何控制(或反饋)。 – 2010-08-30 18:16:24

+0

謝謝菲利普,但看到我的評論如下?這個文件太大了。 – salvationishere 2010-08-30 20:15:59

回答

1

不能使用bcp這一點。 bcp可以給你的最好的是從逗號/標籤/等文件進口。分隔值。您在bcp文檔中看到的所有對xml的引用都是指格式文件,而不是要導入的實際數據。

實際上有兩種方法。最簡單的方法是使用SQL Server Integration Services進行此操作。 This可以幫助你進一步。

你也可以通過reading the xml file將它做到SQL服務器中。然後使用sp_xml_preparedocument解析文件。最後,使用OPENXMLin combination withINSERT來導入數據。

+0

你確定我不能使用BCP嗎?是的,我想最終爲此使用SSIS,但是因爲這個XML非常大,所以會導致內存不足錯誤,所以我最初希望使用BCP將它導入臨時表。我該怎樣才能讀這個XML文件?你建議大容量插入?我不熟悉sp_xml_preparedocument - 是否也會導入此文件? – salvationishere 2010-08-30 18:52:54