431.chapter10. working with flat files
?
二、Bulk Copy Program:
1 定義:一個使用大容量復(fù)制程度API的命令行工具。它可以執(zhí)行下列任務(wù)
(1) 將SQL? Server中的數(shù)據(jù)大容量導(dǎo)出到數(shù)據(jù)文件中
(2) 從查詢中大容量導(dǎo)出樹據(jù)
(3) 將數(shù)據(jù)文件中的數(shù)據(jù)大容量導(dǎo)入到SQL Server中
(4) 生成格式化文件
2 缺點:
(1) 不適宜用戶對數(shù)據(jù)進行復(fù)雜的轉(zhuǎn)換和驗證
(2)有限的錯誤處理能力
3 bcp使用示例
(1) Copy the SQL Server data to a file
C:\>bcp DB..Table out sample.txt -S server -T –c
Starting copy...
63 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total???? : 46???? Average : (1369.57 rows per sec.)
(2) Copy the data from file to SQL Server
C:\>bcp DB..XmlTransfer in XT.txt -S server-T –c
Starting copy...
3 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total???? : 93???? Average : (32.26 rows per sec.)
(3) Copy the SQL Server data to a file, specify the coloumns
C:\>bcp "select field from db..table" queryout sample.txt
?-S server -T -c
Starting copy...
63 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total???? : 15???? Average : (4200.00 rows per sec.)
(4) Create format xml file
C:\>bcp db..table format null -S server-T -c -x -f sample.xml
?4. 幾個常用參數(shù): -t,? -r,? -f
?5.? 特別介紹-h參數(shù)
(1)使用的范圍:當導(dǎo)入數(shù)據(jù)時候有效,可以提高性能減少日志記錄
(2)TABLOCK: 使用table lock在導(dǎo)入數(shù)據(jù)的時候
(3)ORDER:說明源數(shù)據(jù)按照某個字段進行排序。如果這個字段時數(shù)據(jù)庫中表的粗索引一致,將有助于在導(dǎo)入的過程中提高性能,否則此參數(shù)在執(zhí)行過程中將被忽略
三、BULK INSERT
1 bcp vs bulk BULK INSERT
(1) BULK INSERT僅能用來導(dǎo)入數(shù)據(jù), bcp可以導(dǎo)入導(dǎo)出
(2) BULK INSERT在SQL內(nèi)部執(zhí)行,bcp運行在SQL外部,通過ICP來和SQL Server通訊
(3) 對于bcp的操作建議同樣適用于BULK INSERT
2 三個常用參數(shù)的比較
(1) -t, -r, -F
(2) FIELDTERMINATOR, ROWTERMINATOR, FIRSTROW
3 BULK INSERT權(quán)限
(1) 當使用windows驗證模式時,通過驗證windows賬戶是否具有對文件的操作權(quán)限來判定是否可以執(zhí)行BULK INSERT
(2) 當使用mixed驗證模式時,如果使用沒有與windows賬戶相匹配的SQL賬戶,那么將驗證SQL Service賬戶是否對文件的操作具有權(quán)限
4 practise
bulk insert XmlTransfer from 'C:\sample.txt' with (DataFileType='widechar', ROWTERMINATOR=',')
?
總結(jié)
以上是生活随笔為你收集整理的431.chapter10. working with flat files的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python打印格式化与字符串
- 下一篇: 【转】Info.plist中常用的key