Import LOB (BLOB / CLOB) data from files

mssql-cmd - SQL Server interactive and batch query command-line tool »

Download mssql-cmd Free Trial »

mssql-cmd reads every matching file in a folder and stores its bytes in the target LOB column. The file name (without its extension) is written to the name column.

parameters:

schema: schema name (for MySQL: database name)

table: table name

lobfield: the LOB column to import

namefield: the column that receives the file name (without extension)

fileext: only import files with this extension

folder: folder containing the files

recursive: y|n, also read subfolders

importtype: insert|update

Example

mssql-cmd> importlob table=t_file1 lobfield=filedata namefield=id fileext=dat
      > folder="e:\temp\lob" importtype=insert;

Batch example

mssql-cmd dsn="user:password@host:1433/dbname" task=importlob table=t_file1 lobfield=filedata namefield=id fileext=dat folder="e:\temp\lob" importtype=insert quit=y

Use importtype=update when the rows already exist. See also export LOB files.