简体   繁体   中英

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. 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.

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?

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.

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.

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM