Search code examples
sqlsap-asebcp

missing image data


When I transfer data, I sometimes use bcp command. Like this:

---Out
bcp dbname..tableName out tableName.bcp -Uuser -SSERVERNAME -n -Jiso88599


---IN
bcp dbname..tableName in tableName.bcp -Uuser -SSERVERNAME -n -Jiso88599

I have a sybase ase db and I have transfered data with bcp commands. There is an image column on the table. But When I transfered them image column data is missing.

Only a fraction has been transferred.

--- Prod
SELECT datalength(image_column) FROM dbo.tableName where id='5eb9f' --> 57375

--- TEST
SELECT datalength(image_column) FROM dbo.tableName where id='5eb9f' --> 32768

Why?


Solution

  • You have to set the size of the text/image data block with the -T parameter in bcp otherwise it defaults to 32768 bytes (or used to) which, as you have noticed, is not be big enough for your column's data. More info at:

    http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc30191.1550/html/utility/X14951.htm

    You can check the size of the largest row in that column via the below query then size appropriately, alternatively I tend to just set it as high as possible (i.e. just under 2GB) to ensure I get everything.

    select max(datalength(column_name)) from table
    

    One word of warning - this will tablescan the whole table so don't run the query in a production environment on a big table.