IT Community - Software Programming, Web Development and Technical Support

How to insert data from a csv file into a SQL server database?

This is a discussion on How to insert data from a csv file into a SQL server database? within the Database Support forums, part of the Web Development category; I am having a csv file with comma (,) seperated values having some 3 lakh records in it. I have to ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-29-2007, 10:02 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile How to insert data from a csv file into a SQL server database?

I am having a csv file with comma (,) seperated values having some 3 lakh records in it. I have to insert it into the database. Is it possible to insert the data from csv file to database? If so, how? Can anyone help me....
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-29-2007, 10:45 PM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to insert data from a csv file into a SQL server database?

Yes...we can insert the data from csv using bulk insert for example

-- insert the data
bulk insert [dbo].[tablename]
from '<<ToDo: add path to sample.csv>>'
with
(
fieldterminator = ',',
rowterminator = '\n'
)
GO
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-30-2007, 07:54 AM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Default Re: How to insert data from a csv file into a SQL server database?

yes.. its working fine... thanks for ur help
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-09-2007, 10:29 PM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: How to insert data from a csv file into a SQL server database?

Quote:
Originally Posted by kingmaker View Post
Yes...we can insert the data from csv using bulk insert for example

-- insert the data
bulk insert [dbo].[tablename]
from '<<ToDo: add path to sample.csv>>'
with
(
fieldterminator = ',',
rowterminator = '\n'
)
GO
Hi,

Can we able to import data from Excel / Text (Tab Delimited) file into SQL server ?

What are all the file types SQL server supports for import data ?
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-12-2007, 01:19 AM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile Re: How to insert data from a csv file into a SQL server database?

Quote:
Originally Posted by priyan View Post
Hi,

Can we able to import data from Excel / Text (Tab Delimited) file into SQL server ?

What are all the file types SQL server supports for import data ?
yes.. we can able to import data from excel or text file...

Import from EXCEL file:

Follow the steps
1. Right click the database--> Tasks--> Import Data
2. Select the Datasource from the drop down and click next
For excel, select Microsoft excel
For text and csv files, select Flat File source
3. Select destination database and table to insert the data from the file to db


Supported file types:
1. xls
2. csv
3. txt
4. mdb

The above files i have tested..
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-12-2007, 05:14 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: How to insert data from a csv file into a SQL server database?

Hi,

Thanks for your reply..

Can you please provide the command line syntax for importing XLS and MDB file into SQL Server.
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-12-2007, 08:31 PM
$enthil $enthil is offline
D-Web Sr.Programmer
 
Join Date: Apr 2007
Posts: 162
$enthil is on a distinguished road
Smile Re: How to insert data from a csv file into a SQL server database?

Try this query to bulk insert data from a file

syntax:
Quote:
BULK INSERT TableName
FROM 'filepath'
WITH
(
FIELDTERMINATOR = ' |',
ROWTERMINATOR = '|\n'
)
example:
Quote:
BULK INSERT AdventureWorks.Sales.SalesOrderDetail
FROM 'f:\orders\lineitem.tbl'
WITH
(
FIELDTERMINATOR =' |',
ROWTERMINATOR =' |\n'
)
__________________
$enthil
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-01-2008, 09:45 PM
jaydon jaydon is offline
D-Web Trainee
 
Join Date: May 2008
Posts: 1
jaydon is on a distinguished road
Default Re: How to insert data from a csv file into a SQL server database?

where do u insert the script into cause when i import it into vb script. theres alot of problem.. help is required!! thanks
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Multiple records using single Insert Statement vadivelanshanmugam Database Support 0 03-04-2008 09:26 PM
example of Inserting and Retrieving data from xml file hanusoft ASP and ASP.NET Programming 1 11-12-2007 04:13 AM
Copy SQL data structures from one SQL server to another SQL server? arjkhanna Server Management 5 11-05-2007 02:57 AM
reading data from a file using C# oxygen C# Programming 2 08-23-2007 12:48 AM
Data and Database Integrity Testing sudhir Software Testing 1 04-01-2007 08:35 PM


All times are GMT -7. The time now is 11:58 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0