Home Sql Insert Data From File
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Insert Data From File

Advertisement
Insert Data From File is used to insert data from file.

Insert Data From File

     

Insert Data From File is  used to insert data from file.

Understand with Example

The Tutorial illustrate an example to insert data from file. To understand this example, we create a table 'Stu_Table'. The create table statement is used to construct a table 'Stu_Table' with field attribute and data type.

Create Table Stu_Table

Create Table Stu_Table( Stu_Id int, Stu_Name varchar(15),Stu_Class());

The Table 'Stu_Table' is saved in a file abc.txt.

abc.txt

1 Komal 10
2 Ajay 10
3 Santosh 10
4 Rakesh 10
5 Bhau 10
1 aaa 11
2 bbb 11
3 ccc 11
4 ddd 11
5 eee 11
1 iii 12
2 jjj 12
3 kkk 12
4 lll 12
5 mmm 12

Backup query 

The LOAD DATA  INFILE is used to load the data into a text file 'abc,txt'.

LOAD DATA INFILE 'c:/abc.txt' INTO TABLE stu_table
FIELDS TERMINATED BY ' ';

Table Stu_Table

+--------+----------+-----------+
| Stu_Id | Stu_Name | Stu_Class |
+--------+----------+-----------+
| 1      | Komal    | 10        |
| 2      | Ajay     | 10        |
| 3      | Santosh  | 10        |
| 4      | Rakesh   | 10        |
| 5      | Bhau     | 10        |
| 1      | aaa      | 11        |
| 2      | bbb      | 11        |
| 3      | ccc      | 11        |
| 4      | ddd      | 11        |
| 5      | eee      | 11        |
| 1      | iii      | 12        |
| 2      | jjj      | 12        |
| 3      | kkk      | 12        |
| 4      | lll      | 12        |
| 5      | mmm      | 12        |
+--------+----------+-----------+
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2008

Related Tutorials

Ask Questions?    Discuss: Insert Data From File  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
kangleicha
April 15, 2012
txt file to table

Hai, If the format of the log file is like as follows, than how to insert the data into table. Please guide me. id 1 name Komal class 10 *********** id 2 name Ajay class 10 *********** id 3 name Santosh class 10 ***********
kangleicha
April 15, 2012
txt file to table

Hai, If the format of the log file is like as follows, than how to insert the data into table. Please guide me. id 1 name Komal class 10 *********** id 2 name Ajay class 10 *********** id 3 name Santosh class 10 ***********
DMCA.com