数据库设计:文件路径的首选字段长度 [英] Database design : preferred field length for file paths

查看:556
本文介绍了数据库设计:文件路径的首选字段长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在DB字段中存储文件路径( / tmp / aaa / bbb C:\temp\xxx\ yyy ,等)。



给定这个 http://en.wikipedia.org/wiki/Comparison_of_file_systems 以及 http://msdn.microsoft.com/en-us/library/aa365247.aspx ,根据文件系统,理论上可能没有路径的长度限制。



我想将该字段定义为 LONGBLOB VARCHAR(非常高的值)不会明智。我已经考虑过像 VARCHAR(1024)这样的情况,它应该适用于最常见(即使不是全部)情况,而不是太大的DB字段。

解决方案

您可以使用 VARCHAR(MAX) NVARCHAR(MAX)



这些是可变长度字段,意味着它们被设计为存储不同长度的值。



定义 MAX 表示该字段可以高达2GB 。



MSDN (varchar),nvarchar具有类似的文档:


当列数据条目的大小差异很大时,使用varchar。 >

当列数据条目的大小差异很大时使用varchar(max),大小可能超过8,000字节。



I have to store file paths in a DB field (/tmp/aaa/bbb, C:\temp\xxx\yyy, etc.). I can't really tell how long they could be.

Given this http://en.wikipedia.org/wiki/Comparison_of_file_systems and that http://msdn.microsoft.com/en-us/library/aa365247.aspx, depending on the file system there could be theoretically no length limit for a path.

I guess that defining this field as a LONGBLOB or VARCHAR(very high value) wouldn't be wise. I've thought about something like VARCHAR(1024) which should be suitable for most frequent (even if not all) cases, and not too big as a DB field. What would you recommend ?

Thanks.

解决方案

You can use VARCHAR(MAX) or NVARCHAR(MAX).

These are variable length fields meaning they are designed to store values of different length. There is no extra overhead for longer values over shorter values.

Defining MAX means the field can be up to 2GB.

From MSDN (varchar), nvarchar has similar documentation:

Use varchar when the sizes of the column data entries vary considerably.

Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.

这篇关于数据库设计:文件路径的首选字段长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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