保存图像的URL或保存图像文件在SQL数据库? [英] Save image url or save image file in sql database?

查看:331
本文介绍了保存图像的URL或保存图像文件在SQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以保存的图像与2路

We can save an image with 2 way


  1. 上传图片在服务器和存储图像的URL数据库中。

  2. 直接图像保存到数据库中

哪一个更好?

推荐答案

有是由微软研究院一个很好的文件中称的要BLOB或不BLOB

There's a really good paper by Microsoft Research called To Blob or Not To Blob.

它们的大量的性能测试和分析后得出的结论是这样的:

Their conclusion after a large number of performance tests and analysis is this:


  • 如果您的图片或文档通常低于256K大小,将它们存储在数据库中 VARBINARY 列更有效

如果您的图片或文档通常超过1 MB的大小,将它们存储在文件系统被更有效(与SQL Server 2008中的 FILESTREAM 属性,他们'重新仍然事务控制,数据库的一部分下)

if your pictures or document are typically over 1 MB in size, storing them in the filesystem is more efficient (and with SQL Server 2008's FILESTREAM attribute, they're still under transactional control and part of the database)

在这两者之间,这取决于你的使用有点胜负难料的

in between those two, it's a bit of a toss-up depending on your use

如果你决定把你的照片到SQL Server表,我会强烈建议使用一个单独的表用于存储那些图片 - 不存储员工照片在雇员表 - 让他们在一个单独的表。这样一来,员工表可以保持精简,平均和非常有效的,假设你并不总是需要选择员工的照片,也为您的查询的一部分。

If you decide to put your pictures into a SQL Server table, I would strongly recommend using a separate table for storing those pictures - do not store the employee foto in the employee table - keep them in a separate table. That way, the Employee table can stay lean and mean and very efficient, assuming you don't always need to select the employee foto, too, as part of your queries.

有关文件组,请文件和文件组体系结构一个前奏。基本上,你要么从一开始就创建大型数据结构的单独文件组数据库,或更高版本添加一个额外的文件组。让我们把它称为LARGE_DATA。

For filegroups, check out Files and Filegroup Architecture for an intro. Basically, you would either create your database with a separate filegroup for large data structures right from the beginning, or add an additional filegroup later. Let's call it "LARGE_DATA".

现在,只要你有一个新表来创建一个需要存储 VARCHAR(MAX) VARBINARY(MAX)列,可以为大型数据指定该文件组:

Now, whenever you have a new table to create which needs to store VARCHAR(MAX) or VARBINARY(MAX) columns, you can specify this file group for the large data:

 CREATE TABLE dbo.YourTable
     (....... define the fields here ......)
     ON Data                   -- the basic "Data" filegroup for the regular data
     TEXTIMAGE_ON LARGE_DATA   -- the filegroup for large chunks of data

检查出文件组的MSDN介绍,和玩了!

Check out the MSDN intro on filegroups, and play around with it!

这篇关于保存图像的URL或保存图像文件在SQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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