简体   繁体   English

将小文件保存到数据库,保存它们的最佳方法是什么?

[英]saving small files to database, what is the best way to save them?

I have two files that I need to upload to a Sql Database. 我有两个文件需要上传到Sql数据库。 Each file will have it's own table. 每个文件都有自己的表。

File1:  filename.zip (of course a compressed file)
File1:  filename.asc (flat tab delimited file)

I am writing in C# and I am creating a service to send these files up to the database through. 我正在用C#编写,我正在创建一个服务,通过这些文件将这些文件发送到数据库。

What is the best way to save these files? 保存这些文件的最佳方法是什么?

Should I save them different ways since they are two different types of files or can I use File.ReadAllBytes to save them both? 我应该以不同的方式保存它们,因为它们是两种不同类型的文件,或者我可以使用File.ReadAllBytes来保存它们吗?

I am creating the tables, service, and the application to connect to the server so I have full control over what the datatypes will be. 我正在创建表,服务和应用程序以连接到服务器,因此我可以完全控制数据类型。 I've started the process but I'm not 100% sure I have this correct. 我已经开始了这个过程,但我并不是100%确定我有这个正确的。

This is how I created the tables: 这就是我创建表格的方式:

在此输入图像描述

As I said previously, I can change the datatype if need be. 正如我之前所说,如果需要,我可以更改数据类型。 Right now I am planning on making them binary. 现在我打算把它们变成二进制。 Is there a disadvantage to doing it this way? 这样做有缺点吗?

I just a little guidance on the best way to handle this. 我只是对处理这个问题的最佳方法提出了一些指导。

Thanks as always! 一如既往地谢谢!

ADDITIONALLY 另外

I wanted to add, these files are typically under 12kb in size. 我想补充一点,这些文件的大小通常不到12kb。

If the files are really small (less than 8000 bytes each) than you can save them to a column of type BINARY or VARBINARY(MAX) but most files will easily exceed that size. 如果文件非常小(每个小于8000字节),则可以将它们保存到BINARYVARBINARY(MAX)类型的列中,但大多数文件很容易超过该大小。

That said, SQL server does provide a mechanism to store files in a database via the FILESTREAM data type, the File Table or the Remote BLOB Storage . 也就是说,SQL Server确实提供了一种机制,通过FILESTREAM数据类型,文件表或远程BLOB存储数据存储在数据库中。

Another note is that, while it's not very clear from your question, having separate tables for each file is generally not the right way to design a database. 另一个注意事项是,虽然从你的问题中不是很清楚,但是为每个文件设置单独的表通常不是设计数据库的正确方法。 If you're storing similar information, with similar semantics, about the files than you really should have one table with multiple rows, one row for each file. 如果您使用类似的语义存储类似的信息,那么关于文件的实际情况应该是一个包含多行的表,每个文件一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将电影对象保存在其他文件中并将它们与实际收藏夹中的电影对象相关联的最佳方法是什么? - What's the best way to save movie objects inside other files and associate them with the ones in the actual collection? 在 DataSet 中获取更改并将其保存到数据库的最佳方法 - Best way to get changes in a DataSet and save them to the database 保存图像文件和节省内存的最佳方法 - Best way of saving image file and to save memory 绘制对象并对其进行处理的最佳方法是什么? - What is the best way to draw objects and deal with them? 在数据库中保存类类型的最佳方法? - Best way to save type of class in database? 使用 sql 的批量插入将大型 csv 文件保存到 azure 数据库中的最快方法是什么? - What is the fastest way of saving big csv files into azure database using bulk insert from sql? 保存游戏状态的最佳方法是什么? - What is the best way to save game state? 有效提取大型可枚举的小型随机子集的最佳方法是什么? - What is the best way to efficiently extract a small random subset of a large enumerable? 在设置中保存多个字符串的最佳方法是什么? - What is the best way to save multiple strings in settings? 合并大文件的最佳方法是什么? - What is the best way to merge large files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM