在SQL Server中保存图像的最佳实践 [英] Best Practice For Saving Images in SQL Server

查看:128
本文介绍了在SQL Server中保存图像的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多次我想将图像保存到SQL Server。我已经阅读了一些保存图像的做法:

There are many times that I wanted to save an image to an SQL Server. I have read some practices for saving images :

1)上传并保存图像到服务器,保存表内的路径

1) upload and save image to server, save the path inside the table

2)将图像保存为二进制文件

2) save image as binary

3)将图像保存为base64字符串

3) save image as base64 string

4)使用BLOB(我还没有研究它是如何工作的)

4) using BLOB(i haven't researched how it works)

当您从服务器请求图像时,您知道哪种方式更快吗?
你知道哪种方式更好,以免使SQL服务器变慢吗?
你知道其他任何方式哪个更好吗?

Do you know which "way" is faster when you request from server an image? Do you know which "way" is better so as not to make SQL server slower? Do you know any other "way" which is better from the above?

谢谢!

推荐答案

Microsoft已完成一些研究关于这个主题,并得出结论,这取决于你的形象的大小。如果您的大多数图像都是< 256Kb,你应该使用VARBINARY。另一方面,如果它们高于1Mb,那么你应该使用FILESTREAM(通常存储在数据库文件外的文件系统上)。

Microsoft has done some research on this topic and has concluded that it depends on the size of your image. If most of your images are < 256Kb, you should probably use VARBINARY. On the other hand, if they are above 1Mb, then you should use a FILESTREAM (which is usually stored on the filesystem outside the database file).

如果你的图像是链接到其他数据,将记录本身与图像分成不同的表(即创建一个Images表)通常很有用,这样带有数据的表格仍然很小并且易于操作。

If your images are linked to other data, it's often useful to separate the records itself from the images into different tables (i.e. create an Images table) so that the table with the data remains small and easy to manipulate.

这篇关于在SQL Server中保存图像的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆