Bài giảng Kiến trúc cài đặt cơ sở dữ liệu: Chương 2 - Nhập xuất dữ liệu (Exporting and importing data). Chương này gồm có những nội dung chính sau: Lệnh BCP, lệnh BULK INSERT, import and export wizard, project SSIS. Mời các bạn cùng tham khảo.
GV Phi Loan - Khoa CNTT – HUI N i dung • • • • L nh BCP L nh BULK INSERT Import And Export Wizard Project SSIS GV Phi Loan - Khoa CNTT – HUI N ̀ ̀ • SQL Server ̀ ̀ ̀ u ̀ u ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ – L nh BCP – L nh BULK INSERT –D ̀ nh SELECT INTO –D ̀ ̀ ̀I ̀And Export Wizard – Project SSIS GV Phi Loan - Khoa CNTT – HUI BCP (Bulk Copy Program) • Là ti n ích (utility) mà ng i dùng có th th c hi n t d u nh c l nh • Đ ̀ ̀ copy d li u t SQL server thành file c a h u hành hay ng c l i • R t th ̀ ̀ ̀ chuy n l ng l n d li u vào b ng c a SQL server t ch ng trình khác nh t DBMS khác GV Phi Loan - Khoa CNTT – HUI BCP (Bulk Copy Program) GV Phi Loan - Khoa CNTT – HUI Ti n ích BCP • D li u chuy n t ngu n bên vào database c ̀“QL̀ ̀ c g i BCP IN (c ̀ c g i importing) • N u d li ̀ c chuy n t SQL Server ngu ̀ ̀ ̀ c g i BCP OUT (còn c g i exporting) Ngu n ph i ̀ ̀ n (flat file) GV Phi Loan - Khoa CNTT – HUI Ti n ích BCP • Đ ̀ –D –H ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ng GV Phi Loan - Khoa CNTT – HUI ng: ̀ ̀ ̀ ̀ Các yêu c u th c hi n BCP ̀F ̀ li u ch a d li ̀ c nh p vào c n ph i có d ng row/column ̀F ̀ li u nên có ký hi u k t thúc hàng (row terminator) k t thúc c t (column terminator) cho SQL Server có th nh n bi ̀ c truy n d li u ̀C u trúc c a file d li u b ng c a SQL Server c n ph ̀ ng nh t GV Phi Loan - Khoa CNTT – HUI Cú pháp l nh BCP BCP [[database_name.][owner].]table_name {in|out|queryout|format} data_file [-m max_errors] [-f format_file] [-x] [-e err_file] [-F first_row] [-L last_row][-b batch_size] [-n] [-c] [-w] [-N] [-t field_term] [-r row_term] [-i input_file] [-o output_file] [-a packet_size] [-S server_name] [-U login_id] [-P password] [-T] GV Phi Loan - Khoa CNTT – HUI Cú pháp BCP • in|out|queryout|format h ng c a l nh – In: copy d li u t file d li u vào b ng c CSDL – Out: copy d li u t b ng CSDL vào file d –Q ̀ ̀ ̀ ̀ ̀ ̀ ̀ n –F ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ - ̀- ̀- ̀ ̀-N ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀K ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ T ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ n GV Phi Loan - Khoa CNTT – HUI a li u ̀ ̀ ̀ ̀ f 10 GV Phi Loan - Khoa CNTT – HUI 57 Data Flow Task • L ̀ ̀ –H –H • C ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ c dataset ̀D ̀F ̀T ̀ ̀ ̀ ̀ ̀ a tab Control Flow ̀ o tab Data Flow ̀ ̀ ̀ ̀ ̀ ̀ ̀̀ ng toolbox: – Data flow source adapters – Data flow transformations – Data flow destination adapters GV Phi Loan - Khoa CNTT – HUI 58 P i Data flow • Data Flow Sourcè ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ng • Data Flow Transformations̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ u • D ̀F ̀D ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ i GV Phi Loan - Khoa CNTT – HUI 59 T ̀ •C ̀ ̀ ̀ ̀ ̀ n ̀ ̀F ̀“ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ n •C ̀ ̀ ̀ ̀ ̀F ̀D ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ n •X ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ch GV Phi Loan - Khoa CNTT – HUI 60 Data Flow Source GV Phi Loan - Khoa CNTT – HUI 61 Data Flow Destination GV Phi Loan - Khoa CNTT – HUI 62 Data Flow Destination GV Phi Loan - Khoa CNTT – HUI 63 V̀ ̀ ̀ a GV Phi Loan - Khoa CNTT – HUI 64 C ̀ ̀ ̀ (transformation) • • • • ̀ i Logical row-level transformations Multi-input or multi-output transformations Multi-row transformations Advanced data -preparation transformations GV Phi Loan - Khoa CNTT – HUI 65 GV Phi Loan - Khoa CNTT – HUI 66 GV Phi Loan - Khoa CNTT – HUI 67 GV Phi Loan - Khoa CNTT – HUI 68 GV Phi Loan - Khoa CNTT – HUI 69 Data Flow Transformations GV Phi Loan - Khoa CNTT – HUI 70 Data Flow Transformations GV Phi Loan - Khoa CNTT – HUI 71 ... max_errors] [-f format_file] [-x] [-e err_file] [-F first_row] [-L last_row][-b batch_size] [-n] [-c] [-w] [-N] [-t field_term] [-r row_term] [-i input_file] [-o output_file] [-a packet_size] [-S server_name]... file d –Q ̀ ̀ ̀ ̀ ̀ ̀ ̀ n –F ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ - ? ?- ? ?- ̀ ̀-N ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀K ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ T ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ n GV Phi Loan - Khoa CNTT – HUI a li u ̀ ̀ ̀ ̀ f 10 Cú pháp BCP... Phi Loan - Khoa CNTT – HUI 13 Cú pháp BCP • -F first_roẁ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀M ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀1 • -L last_roẁ ̀ ̀ ̀ ̀ ̀ ̀ ̀ p • ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ ̀ n 2^6 3-1 GV Phi Loan - Khoa CNTT