在SQL Server数据库中保存字体的最佳方法 [英] Best Way to Save a Font in SQL Server database

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

问题描述

在知道可以从不同环境(Windows/Linux)和语言(Java/PHP/Python/C#)访问该字体的同时,哪种方法是在SQL Server数据库中插入字体的最佳方法?

Which is the best way to insert a font in a SQL Server database, while knowing that this font can accessed from different environments (Windows/Linux) and languages (Java/PHP/Python/C#)?

我有一种情况,我应该从C#Winforms应用程序中插入一个Font并从Java应用程序中获取该字体,目前我正在从Java中插入Font.NameFont.StyleFont.Size字体使用Font.Decode();方法.

I have a case where I should insert a Font from a C# Winforms application and get this font from Java application, and currently I'm inserting Font.Name, Font.Style and Font.Size and from Java I'm retrieving the font using Font.Decode(); method.

它在许多情况下都可以工作,但是我认为将字体文件传输到数据库并从数据库中获取字体文件.ttf可能更好,方法是将自定义构造的字符串与字体相关联,以识别字体

And it works in many cases, but I thought it might be better to transfer the font file to the database and get the font file .ttf from the database by associating a custom constructed string to identify the font with its associated file.

例如:Font NameFont SizeFont Style + Font File,因为有时该字体未安装或在另一个系统上具有不同的名称(对我而言,字体非常重要).

eg: Font Name, Font Size and Font Style + Font File, because sometimes that font is not installed or has a different name on another system (font is very important in my case).

推荐答案

Microsoft Research有一篇非常好的论文,名为

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列中会更有效

  • if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient

如果图片或文档的大小通常超过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表中,我强烈建议使用一个单独的表来存储这些图片-不要将employee foto存储在employee表中-请将它们保存在单独的表中.这样,假设您并不需要总是选择员工图片作为查询的一部分,那么Employee表就可以保持精简,平均和高效.

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!

这篇关于在SQL Server数据库中保存字体的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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