可以有不同类型多媒体的数据字段
我正在创建一个数据库表,其中一列可以采用所有可能的多媒体(文本、视频、音频、图像)的形状。在不过度创建几个不同的列或多个表的情况下,我决定应该有一个文件指针来指向数据驻留在服务器上的位置,并有一个额外的列来指示给定行中存在的数据类型。
我想知道这是否是一个好的设计策略或者是否有更好的现有替代方案?
非常感谢,
帕里贾特
I am creating a database table, one of the columns can take the shape of all possible multimedia (text,video,audio,image). Without going into overkill of creating several different columns or multiple tables I decided that I should rather have a file pointer that points to where the data resides on the server and have an extra column that indicates the type of data present for the given row.
I want to know if this is a good design strategy or if there are better existing alternatives?
Thanks much,
Parijat
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个很好的策略。除了文件类型之外,我建议添加一个列来存储文件的长度(以字节为单位),以便在需要在
Content-length
中提供文件时,避免从文件系统中检索它。例如,标题。如果您希望所有文件的大小相对一致(不像视频文件那样太大),则最好将数据作为二进制 blob 存储在数据库中,但考虑到您希望有不同的媒体类型,并且文件大小可能非常不同,我认为将文件保留在文件系统中并从数据库指向它们更有意义。
This is a fine strategy. In addition to the type of file, I would recommend adding a column that stores the length in bytes of the file, to save you retrieving it from the filesystem when you need to supply it in a
Content-length
header, for example.If you expected all files to be of a relatively consistent size (none too large like video files), it might be preferable to store the data as binary blobs in the database, but given that you expect diverse media types and possibly very diverse file sizes, I think it makes more sense to keep the files in the filesystem and point to them from the database.