Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to import data from .csv file to a table

Author  Topic 

arthiasha
Starting Member

40 Posts

Posted - 2012-10-18 : 00:21:53
Hi experts,
I have a .csv file which i need to import data from it to a table called temp in my db. How do i do bcp in, to import the data to the table.
I also created a format file for temp. can i have the syntax atleast
Thanks in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-18 : 00:43:03
you've few options

1. SSIS export import wizard
2. OPENROWSET
3. BULK INSERT

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-18 : 01:10:13
You can also do BULK INSERT..........


bulk insert YourTableName
from 'YourFilePath'
with (fieldterminator=','
,rowterminator='\n')




--
Chandu
Go to Top of Page

arthiasha
Starting Member

40 Posts

Posted - 2012-10-18 : 01:46:47
Can i have a bcp script to do bulk insert?
C:\inetpub\wwwroot\db>bcp temp in .\employee.csv -d mydb -S ACER-PC\SQLEXPRESS -U sa -P sa -t,

is my script correct?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-18 : 13:02:00
quote:
Originally posted by arthiasha

Can i have a bcp script to do bulk insert?
C:\inetpub\wwwroot\db>bcp temp in .\employee.csv -d mydb -S ACER-PC\SQLEXPRESS -U sa -P sa -t,

is my script correct?


Yep...you can first create table and then use syntax like

bcp <tablename> in <filepath> -T -c

if you're using windows authentication


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -