Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a blob in SQL Server

Tags:

I want to do some tests to my database (like turning off the machine while it's still writing something). To do this, I'm planning to insert a movie file into the database with 700mb, so that I can have time to insert it and turn it off (instead of being something done instantaneously).

I'm using SQL Server 2008, and the closest I can find in the data types is Binary(50). Is this enough for what I want?

I want to know which data type must the column that will store this large file be.

like image 689
RagnaRock Avatar asked Nov 23 '11 10:11

RagnaRock


People also ask

How do I declare a BLOB in SQL?

You should use VARBINARY(MAX) : Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes.

Can we store BLOB in SQL Server?

Remote BLOB store (RBS) for SQL Server lets database administrators store binary large objects (BLOBs) in commodity storage solutions instead of directly on the server. This saves a significant amount of space and avoids wasting expensive server hardware resources.

Do we have BLOB data type in SQL Server?

SQL Server provides the varbinary(MAX) data type to store BLOBs although the older Image data type is still available. The BLOB data can be read in .


1 Answers

Binary(50) will hold 50 bytes - this is not going to be enough to hold 700mb.

From MSDN:

binary [ ( n ) ]

Fixed-length binary data with a length of n bytes, where n is a value from 1 through 8,000. The storage size is n bytes.

You should use VARBINARY(MAX):

Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes.

You could also use Image, though it is deprecated.

like image 160
Oded Avatar answered Sep 22 '22 23:09

Oded