简体   繁体   English

从CSV文件导入到SQL错误

[英]Import from CSV file to SQL Error

I have a CSV file with following columns 我有一个包含以下各列的CSV文件

ID                    State                     Email
1020202034566949       LA                     r1@abc.com
1020202034543245       CA                     r2@abc.com
1020202034521234       TX                     r3@abc.com
1020202034521345       TN                     r4@abc.com
1020202034589789       NY                     r5@abc.com

But wen I import them to sql table I get following result 但是我将它们导入到SQL表中我得到以下结果

     ID                         State                     Email
    1.020202034566949E+15        LA                     r1@abc.com
    1.020202034543245E+15        CA                     r2@abc.com
    1.020202034521234E+15        TX                     r3@abc.com
    1.020202034521345E+15        TN                     r4@abc.com
    1.020202034589789E+15        NY                     r5@abc.com

as the column is ID I need it to be exactly same like what I get, 因为该列是ID,所以我需要使其与获得的ID完全相同,

I tried changing the format in Excel with various formats as number without decimals, special category and all but are of no use. 我试图用各种格式更改Excel中的格式,如不带小数的数字,特殊类别,但都没有用。

You need to pre format the cell in excel to "number", set decimal place to 0, currently it will be set at general but this struggles with larger numbers such as yours. 您需要将excel中的单元格预格式化为“数字”,将小数位设置为0,当前通常将其设置为该值,但这在较大的数字(例如您的数字)中很难解决。

Had the same issue myself earlier. 我本人也遇到过同样的问题。

EDIT 编辑

As commented below you will obviously need to account for such a large number in SQL server bigint will be enough. 如下所述,您显然需要在SQL Server中考虑这么大的数目, bigint就足够了。

EDIT 2 Think the only way for you to go would be to set this as a text field, I've just tested and it doesn't actually alter the number this way. 编辑2认为您唯一的选择就是将其设置为文本字段,我刚刚进行了测试,但实际上并没有以这种方式更改数字。

The issue is that excel will only allow accurate numbers of up to 15 charactors. 问题是excel只允许最多15个字符的准确数字。

The workaround here being you have it as a text field in excel, then cast this as a big int during the import. 解决方法是在excel中将其作为文本字段输入,然后在导入期间将其强制转换为大整数。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM