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

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.

Up vote 1 down vote favorite share g+ share fb share tw.

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. Sql-server import link|improve this question edited Jan 22 '10 at 15:15marc_s176k14142283 asked Jan 22 '10 at 14:42Nicolas Cadilhac1,76711123 51% accept rate.

I tried it but I forgot to mention that I have another column in this table and its value must be set to the same int for all rows. So I could not make the import tool work. Of course I could see if I can edit my text file to put this field in each row.

– Nicolas Cadilhac Jan 22 '10 at 15:05 After modifying my input file to add the constant on each row, I was able to use the tool you mentioned (import in SSMS). Thanks. – Nicolas Cadilhac Jan 22 '10 at 15:28.

You can use bulk insert to do this BULK INSERT your_table FROM 'c:\your_file. Txt' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) GO.

Sorry I forgot that I have another column in this table and its value must be set to the same int for all rows. – Nicolas Cadilhac Jan 22 '10 at 15:04 Then bulk insert into temp table and select needed values (+ constants) from there into your main table. – Arvo Jan 22 '10 at 15:08 I chose Keith's solution because it worked without a lot of effort in this case.

Maybe your solution would have worked too with more details after I updated my question. So, thanks anyway. – Nicolas Cadilhac Jan 22 '10 at 15:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions