分割字符串,然后插入到数据库 [英] Splitting a string and insert into a database

查看:208
本文介绍了分割字符串,然后插入到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置一个SQLServer防爆preSS和创造我所需要的表。这里不过在那里我遇到一个问题。

I've setup a SqlServer Express and created the tables i need. Here's however where I run into a problem.

我有这个文本文件包含大量的不同的信息,这里的和例如:

I have this textfile containing lot's of different info, here's and example:

Line1: 00001, Some name, Address, Email
Line2: 00002.. 

我如何分割线,这些都是分开用逗号相关的信息之间,并移动到正确的列在我的数据库中的信息?

How do I split lines, which are all divided with commas between the relevant information and move the information into the correct columns in my database?

ID      | Name        | Address      | Email    |   <-- Columns

000001  | Some name   | Some street  | @mail    |   <-- Data inserted

000002 etc.

我希望你明白我的问题,我做了我所能想象的。

I hope you understand my question, I did my best to visualize it.

在此先感谢。

推荐答案

http://midnightprogrammer.net/post/Import-CSV-File-Into-SQL-Server-Using-Bulk-Insert.aspx

BULK INSERT Contact
FROM 'c:\TestData.csv'  -- Full path of the Delimited file
WITH
(
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '\n'   --Use to shift the control to next row
)

如果你只是经过一次关闭导入右键点击你的数据库管理工作室 - >任务 - >导入数据,选择平面文件源,然后按照向导

or if you're just after a once off import right click your db in management studio -> tasks -> import data, choose flat file source and follow the wizard

这篇关于分割字符串,然后插入到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆