How to Store and Retrieve Images Using SQL Server (Server Management Studio)

前端 未结 2 1899
遇见更好的自我
遇见更好的自我 2021-01-18 07:28

I am having difficulties when trying to insert files into a SQL Server database. I\'ll try to break this down as best as I can:

  1. What data type should I be u

相关标签:
2条回答
  • 2021-01-18 07:47

    The image type is deprecated, so don't use that.

    The short answer is to use the FILESTREAM type if this is SQL 2008, or varbinary(max) if it's 2005 or earlier.

    The better answer is to use the FILESTREAM type if this is SQL 2008, and not store images in the database at all otherwise. Databases aren't built for this type of thing and throwing BLOBs in there can hurt performance significantly. FILESTREAM sidesteps the issue by storing the actual data on the file system; everything else is a sub-standard solution.

    As for how to read and write to a varbinary column if you choose to take this non-ideal approach, it's going to be represented as a stream in PHP. That's what you get out of a query as the column value, and I believe that's what you have to put in as a parameter.

    0 讨论(0)
  • 2021-01-18 08:02

    There is bulk insert util acceptable from command line bcp.exe. Read this for more information how to insert binary data into MS SQL through t-sql.

    0 讨论(0)
提交回复
热议问题