SQL Server中图像字段内容的大小是多少?

Fab*_*bio 42 t-sql sql-server datalength

我在SQL Server中有一个表.此表具有图像字段,应用程序将文件存储在其中.

有没有办法使用T-SQL读取图像字段中的文件大小?

Phi*_*hil 77

SELECT DATALENGTH(imagecol) FROM  table
Run Code Online (Sandbox Code Playgroud)

请参阅MSDN

  • 在_megabytes_中,它将是`SELECT DATALENGTH(imagecol)/ 1048576.0 FROM table` (5认同)
  • 结果将是*字节数*. (3认同)

小智 6

不同的显示样式:

SELECT DATALENGTH(imagecol) as imgBytes,
       DATALENGTH(imagecol) / 1024 as imgKbRounded,
       DATALENGTH(imagecol) / 1024.0 as imgKb,      
       DATALENGTH(imagecol) / 1024 / 1024 as imgMbRounded,
       DATALENGTH(imagecol) / 1024.0 / 1024.0 as imgMb
FROM   table
Run Code Online (Sandbox Code Playgroud)

输出示例:

imgBytes    imgKbRounded    imgKb       imgMbRounded    imgMb
68514       66              66.908203   0               0.065340041992
Run Code Online (Sandbox Code Playgroud)