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

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

问题描述

我们可以使用两种方式保存图像

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的

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表,我强烈建议使用单独的表来存储这些图片 - 不要将员工foto存储在员工表中 - 将它们保存在单独的表中。这样,员工表可以保持精益,平均而且高效,假设您不一定需要选择员工照片,作为您的查询的一部分。

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".

现在,只要有一个新的表创建需要存储的新表V $($)$ V $ $ c>或 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天全站免登陆