Sabtu, 13 April 2013

QUERY LOAD DATA INFILE



Load data infile digunakan untuk memasukkan data ke tabel di dalam database dari sebuah file dari suatu folder.

Format Umum :
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
    [REPLACE | IGNORE]
    INTO TABLE tbl_name
    [CHARACTER SET charset_name]
    [{FIELDS | COLUMNS}
        [TERMINATED BY 'string']
        [[OPTIONALLY] ENCLOSED BY 'char']
        [ESCAPED BY 'char']
    ]
    [LINES
        [STARTING BY 'string']
        [TERMINATED BY 'string']
    ]
    [IGNORE number LINES]
    [(col_name_or_user_var,...)]
    [SET col_name = expr,...]
Contoh 1:
LOAD DATA INFILE 'C:/testsql/databuku.txt'
INTO TABLE t_buku;
Contoh 2:
LOAD DATA INFILE 'C:/testsql/databuku.txt'
INTO TABLE t_buku
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n';
Contoh 3:
LOAD DATA INFILE 'C:/testsql/databuku.txt'
INTO TABLE t_buku
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
(CODE,judul,tahun_terbit);