[英]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字节),则可以将它们保存到
BINARY
或VARBINARY(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.