Large Text and Images In SQL

后端 未结 7 2191
栀梦
栀梦 2021-02-08 19:02

Is it a good idea to store large amounts of text (eg html pages) inside your SQL database? Or is it a better idea to store it as html files in the filesystem?

The same g

相关标签:
7条回答
  • 2021-02-08 20:02

    Storing binary data (documents, images etc) in the database has some advantages.

    • You can commit the update of the document itself in the same transaction as the information (name, date etc) you want to store about the document. This means you don't have to worry about writing your own two-phase commit (although ISTR that SQL Server 2008 has a solution for this).

    • You can back up the whole lot (documents and metadata) at once, without worrying about having to synchronise the database with the file system

    • You can deliver documents very simply over .NET web services, since they come straight out into DataTables, and are serialised effortlessly just by putting the DataTables into a DataSet and passing it.

    • You can apply database security to the objects, as to the rest of your data, and not have to worry about network file permissions.

    It does have some disadvantages too:

    • Backups can get very large

    • The size of the binary object in the database can be quite a bit larger than the file it originally came from, and therefore in a client-server environment, it can increase the time taken to open them across the network.

    • Depending on the application, you might need to consider the load on the database server if it has to serve up a lot of large documents.

    All that said, it's a technique I use extensively, and it works very well.

    0 讨论(0)
提交回复
热议问题