2012年3月27日星期二

Bcp with QA : TABLOCK option

User <Brett Kaiser SQLTeam Scrub> a few days earlier
gave me the TRICK to launch BCP through the QA :

DECLARE @.cmd varchar(8000) ;

SET @.cmd = 'bcp ' + 'TablePerson'
+ ' out ' + 'C:\Program files\MyExportFile.dat'
+ ' -c -t ' + ''
+ ' -r ' + '\n'
+ ' -U ' + 'DBA' +' -P ' + 'SQL' +' -S ' + @.@.servername

EXEC master..xp_cmdshell @.cmd ;

It works GREAT but I'm trying to add the Tablock option at the end to have better performances

+ ' h ' + '"TABLOCK"'

But then I have this error :

Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Impossible de trouver la procdure stocke 'TABLOCK'.Originally posted by Karolyn
<SQLTeam Scrub>

Hey...

You can't, and shouldn't

Why do you want to?|||Hem, ... to lock the table while loading the data (?!?)

I use it with the bulk insert and it cuts by 5 the time to load the data

Bulk Insert DB..Tbl
From 'MyPath\MyFile'
With (FieldTerminator = '',
RowTerminator = '\n',
CodePage = 'ACP',
TabLock) ;|||Are you trying to output the ss data to a file (which is what you are doing) ?|||Ok, now we've changed direction...

I would use BULK INSERT...and bcp out...

BOL:

TABLOCK

Specifies that a table-level lock is acquired for the duration of the bulk copy operation. A table can be loaded concurrently by multiple clients if the table has no indexes and TABLOCK is specified. By default, locking behavior is determined by the table option table lock on bulk load. Holding a lock only for the duration of the bulk copy operation reduces lock contention on the table, significantly improving performance.

Which I interprete to mean that you're using the default locking behavior...|||Hem, ... to lock the table while loading the data (?!?)

Change the "out" to "in" if you are loading the data into sql server.|||The BULK INSERT works fine with the TABLOCK option

but the BCP command doesn't recognize this option

OK >>> Bulk Insert ... With (Tablock)
KO >>> EXEC master..xp_cmdshell BCP ... -h "Tablock";

没有评论:

发表评论