.Net Compression and SQL Server 2005 NVARCHAR(MAX) - sql-server

Can I safely store a .Net compressed memory stream (System.IO.Compression) in an SQLServer 2005 NVARCHAR(MAX) field? SQLServer 2008 is not an alternative.

Use VARBINARY(MAX) for binary data - VARCHAR(MAX) and NVARCHAR(MAX) are for character-data (strings).

You'd be better off using varbinary(max)

I would think varbinary(max) is more suitable. Remember that there is a max size of 2GB.

A Stream is just a pointer to data, so you cannot store the stream into SQL Server, you can store the data that this stream points to. As you mention the System.IO.Compression namespace I suppose you mean either DeflateStream or GZipStream which both contain binary data. The appropriate type to store binary data in SQL is VARBINARY(MAX).

Related

SQLite linked server on SQL Server

I've a SqLite linked server on SQL Server 2008.
I need to import an image column from SQL Server into my SQLite database.
Is that possible?
If yes in what kind of SQLite column to I need?
I need to transform ..... I think
Please help me
From: here
NULL. The value is a NULL value.
INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
BLOB. The value is a blob of data, stored exactly as it was input.
and, from: here
image: Variable-length binary data from 0 through 2^31-1
(2,147,483,647) bytes.
I suppose that BLOB should be your needed type
edit:
by the way be careful with the "image" type:
Important
ntext, text, and image data types will be removed in a future version of MicrosoftSQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.
Image column equivalent in SQLite would be BLOB.
You can accomplish your import task by writing script which connects to both SQL Server and SQLite database, then reads data from one and inserts it into another.
When you insert your data, be sure to use prepared statements and bind variables with proper data type. For example, if using Perl, use SQL_BLOB binding:
use DBI qw(:sql_types);
my $dbh = DBI->connect("dbi:SQLite:my.db");
my $blob = `cat foo.jpg`; # you should read it from SQL Server here
my $sth = $dbh->prepare("INSERT INTO mytable VALUES (?)");
$sth->bind_param(1, $blob, SQL_BLOB);
$sth->execute();

tables with multiple varbinary columns

If i have a table with varbinary(Max) datatype and have FILESTREAM attributes on the column. Now I need to have to store another binary data but without FILESTREAM attribute. So, if I add another column with VARBINARY(MAX) datatypes on the same table would there be any performance issue? Do I gain faster performance if I separate a table with FILESTREAM attributes and Create another separate table to store other VARBINARY(MAX) data?
for your this question.you can.
Filestream is the new feature in sqlserver2008,and in 2012 ,that change the name ,call fileTable.
I tested it.this feature is use the DB manage the file .and up file about 5M/s.
for your other column,if you not open the filestream,the file will be change the binary ,and store in sqlserver data file.
open the filestream,the file will store the server, and managed by sqlserver.
for your second question,i am not 100% sure,but if you use the filestream,it's will gain more effiencit,need to attention the backup and store.
one years ago,i implemented this function in our system,and i have the shcame,if you want ,i will send you.
sorry,my english is not good.
your performance might be effected if you add another VARBINARY(MAX) on the same table
When the FILESTREAM attribute is set, SQL Server stores the BLOB data in the NT file system and keeps a pointer the file, in the table. this allows SQL Server to take advantage of the NTFS I/O streaming capabilities. and reduces overhead on the SQL engine
The MAX types (varchar, nvarchar and varbinary) and in your case VARBINARY(MAX) datatype cannot be stored internally as a contiguous memory area, since they can possibly grow up to 2Gb. So they have to be represented by a streaming interface.
and they will effect performance very much
if you are sure your files are small you can go for VARBINARY(MAX) other wise if they are larger thab 2gb FILESTREAM is the best option for you
and yeah i would suggest you Create another separate table to store other VARBINARY(MAX) data

SQL Server 2008: Collation for UTF-8 code page 65001

There is a need to save an XML in UTF-8 encoding and then use it in T-SQL code to extract data.
Default database collation is SQL_Latin1_General_CP1_CI_AS.
I don't know if it is possible to save and work with UTF-8 data in SQL Server 2008, but I have an idea to use collation with code page of UTF-8 (65001) on the XML column in order to save the data in UTF-8.
Does anybody know if it is possible or have another idea on how to work with UTF-8 data in SQL Server?
If you're dealing with xml data, store it as the xml data type. That should take care of any concerns you have (i.e. how to store it) and you'll save yourself the work of having to convert it to xml when you do work on it (e.g. xpath expressions, xquery, etc).
You can store all Unicode characters in xml or nvarchar columns. It does not matter what collation you use. A handful of rare Chinese characters (from the supplementary plane) may be stored as pairs of nchars (surrogate pairs). But there is no loss of data.
NVARCHAR column should do the job just fine.

suitable data type to save string larger than 8000 charachter

what is the suitable data type to save string more than 8000 character in SQL database?
For SQL Server 2005+ varchar(max) or nvarchar(max) depending on whether you need to save as unicode or not.
If you don't have this requirement (or anticipate ever needing it) the varchar option is more space efficient.
You don't give a specific version of SQL Server in your question. Pre 2005 it would have been the text datatype.
NB: In answer to your comment use 'varchar(max)' exactly as written. Don't substitute a number in for "max"!

What data type is best for storing comments in SQL Server?

What is an effective datatype in SQL 2005 to store a comments field?
If the comment will always fit in 8000 chars then varchar(8000) (or nvarchar(4000)).
Otherwise a varchar(max)
That depends on whether or not you limit the comment length. On SO, nvarchar(600) does it. On a blog, you probably want nvarchar(max).
Apparently SQL 2005 only supports:
varchar(max) Variable-length non-Unicode data with a maximum length of 2^31 characters.
If you need unicode character strings,
nvarchar(max) Variable-length Unicode data with a maximum length of 2^30 characters.
text is also supported as a datatype. Use this site if you need more reference:
http://www.teratrax.com/sql_guide/data_types/sql_server_data_types.html

Resources