Read + Write + Report
Home | Start a blog | About Orble | FAQ | Blogs | Writers | Paid | My Orble | Login

SQL Script to Load an external csv file in tables

November 19th 2010 07:49
Repost by Dr.Code:
1. Suppose we have a table users:
CREATE TABLE `users` ( `id` INT UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 20 ) NOT NULL ) ENGINE = MYISAM;

2. We have a csv file 'c:\Users\jiansen\jiansen_dir \mysqlfile.csv' as:

Tom,1996-12-29
Jerry,1985-12-29
3. We use the following command to insert the csv file in table users in SQL:
LOAD DATA INFILE 'c:/Users/jiansen/jiansen_dir /mysqlfile.csv' INTO TABLE users
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
4. If we use SQL server, we use:
BULK INSERT users
FROM 'c:\Users\jiansen\jiansen_dir \mysqlfile.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = 'n'
)

17
Vote
Add To: del.icio.us Digg Furl Spurl.net StumbleUpon Yahoo


   
subscribe to this blog 


   

   

   

Add A Comment

To create a fully formatted comment please click here.


CLICK HERE TO LOGIN | CLICK HERE TO REGISTER

Name or Orble Tag
Home Page (optional)
Comments
Bold Italic Underline Strikethrough Separator Left Center Right Separator Quote Insert Link Insert Email
Notify me of replies
Your Email Address
(optional)
(required for reply notification)
Submit
More Posts
1 Posts
1 Posts
1 Posts
109 Posts dating from May 2008
Email Subscription
Receive e-mail notifications of new posts on this blog:
0

Jiansen Lu's Blogs

2092 Vote(s)
1 Comment(s)
54 Post(s)
1174 Vote(s)
0 Comment(s)
24 Post(s)
6034 Vote(s)
2 Comment(s)
181 Post(s)
6052 Vote(s)
53 Comment(s)
103 Post(s)
Moderated by Jiansen Lu
Copyright © 2012 On Topic Media PTY LTD. All Rights Reserved. Design by Vimu.com.
On Topic Media ZPages: Sydney |  Melbourne |  Brisbane |  London |  Birmingham |  Leeds     [ Advertise ] [ Contact Us ] [ Privacy Policy ]