开发者

How to import data from a file into a single column of a SQL Server database?

I have a very simple table with only one column (+ the key column). This column is a varchar(N) type. I would like to import data from a text file. The file looks like this:

string1
string2
.
.
.
stringZ

I don't know how to generate a script to insert these values into the table. Or is there an even simplier tool to import in such a scenario?

Update: sorry I forgot that I have another column in this table and its value must be set to开发者_运维问答 the same int for all rows.

Thanks for your help.


You can use bulk insert to do this

BULK
INSERT your_table
FROM 'c:\your_file.txt'
WITH
(
   FIELDTERMINATOR = ',',
   ROWTERMINATOR = '\n'
)
GO


There are several approaches from writing your own little utilty to do it, to using BCP or other built in tools. Probably the easiest approach would be to use the Import Data wizard - in SSMS right click on the database you want to import into, choose Tasks and then Import Data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜