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  
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
  #2  
Old 10-29-2007, 10:45 PM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 881
kingmaker is on a distinguished road
Send a message via MSN 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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
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  
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  
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  
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  
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  
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 Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How i should insert record into Oracle database? shaalini Server Management 6 06-10-2009 12:59 AM
Unable to save string data into a table in SQL Server 2005 database tskmjk VB.NET Programming 0 10-07-2008 03:12 AM
Read database table and write data to text file. wlisp C# Programming 1 07-23-2008 01:39 AM
Insert Multiple records using single Insert Statement vadivelanshanmugam Database Support 0 03-04-2008 09:26 PM
Data and Database Integrity Testing sudhir Software Testing 1 04-01-2007 08:35 PM


All times are GMT -7. The time now is 06:00 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0