将数据从 .txt 文件导入到 SQL Server 2005 Express
我有一个制表符分隔的 .txt(非常小文件,只有 10 到 15 个数据集),该文件有一些列,如 PrdName、PrdSize、PrdWeight、PrdCode 等。
现在我想导入 PrdSize 和 PrdCode 两列,并将其导入到我的数据库表的列中。 我已经创建了列,但如何创建导入子句并将数据从 .txt 文件传输到 SQL Server?谢谢
I have a tab separated .txt (Very Small file with just 10 to 15 datasets) and this file is having some columns as PrdName, PrdSize, PrdWeight, PrdCode and so on.
Now I want to import the two columns which are PrdSize and PrdCode and import it in the columns of my Database table.
I have created the columns but how do I create import clause and transfer data from .txt file to SQL Server? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下这篇文章: 使用 SQL Server 2005 Express 导入/导出数据,您可以使用多个选项。
Take a look at this post: Import/Export data with SQL Server 2005 Express, there are multiple options that you can use.
由于您拥有 Express 版本,因此您需要使用 BCP 或用别的东西写一个程序。
Since you have the express edition you'll need to either use BCP or write a program with something else.
如果您有大量数据,或者需要自动化该过程,请务必考虑前面提到的 BCP。然而,我经常使用 excel 将来自奇怪来源的一次性数据源(几百到几千)行数据加载到 SQL Server 中,方法如下:
将数据导入 excel(这通常很容易),假设您得到A 列包含“Prdsize”,B 列包含 PrdCode,在 C 列中输入公式:(
换句话说,使用 Excel 公式创建语法正确的 SQL - 您可能需要在字符串值等周围添加引号)
,然后将该公式粘贴到所有然后将生成的 sql 插入语句复制/粘贴到 SQL Management Studio 或任何其他可以执行 SQL 的工具中并执行它。
绝对是一项“手动”工作,但对于一次性数据加载来说,这确实很棒。
PS:您需要验证 XL 公式和生成的 sql 语法 - 我的示例很接近,但我没有测试它。
If you have a large amount of data, or need to automate the process, definitely look into BCP as mentioned already. However, I often use excel to load one-time data sources (a few hundred to a few thousand) rows of data from odd sources into SQL Server by doing the following:
Get the data into excel (that's usually easy), assuming you get column A with 'Prdsize' and column B with PrdCode, in column C put the formula:
(in other words create syntactically correct SQL using an Excel formula - you may need to add quotes around string values etc)
and then paste that formula all the way down the column C. Then copy/paste the resultant sql insert statements into SQL Management Studio, or any other tool that can execute SQL and execute it.
Defintely a 'manual' effort, but for one-time data loads it words great.
PS: You'll need to verify the XL formula and the resultant sql syntax - my example is close, but I didn't test it.