Can source code examples be kept in a SQL database while retaining all formatting? If so - sql

Can source code examples be kept in a SQL database while retaining all formatting (tabs, newlines, etc.)? If so what data type would be used?

Yes, use a TEXT type (or MEDIUMTEXT or LONGTEXT - you get the idea)

A BLOB type (varbinary) would definitely work, although databases shouldn't mangle text that's stored as varchar either.

The best in Sql Server: nvarchar(max)

You can upload this into a blob data type. SQL 2008 comes with the capability of storing the entire executable file in the database.

Related

How to get the length of the contents of a varbinary field with SQL in Advantage Database Server db?

Does anyone know if it is possible to get the length of the contents of a varbinary field using SQL with Advantage Database Server V11?
Regards
The obvious function to look for would be LENGTH(field) or LEN(field) (see online help).
If those only work on character fields, then you can always cast.

Storing 30k-char strings, should I use NVARCHAR(max)?

From what I fond on internet, I should be using NVARCHAR(max) to store some strings that contain up to 30k characters. I don't need to search through the strings, only store and retrieve it. The type TEXT seems obsolete, and VARCHAR isn't as friendly as NVARCHAR about Unicode, so I should be using NVARCHAR(max), right ?
Secondly, for now I'm using some sql database of a free webhosting service, i'm creating the structure via the phpmyadmin, and when creating columns it doesn't suggest NVARCHAR, only VARCHAR and other types. Is NVARCHAR still available, maybe with a DDL command ? The sql version is 5.5.32
Thanks and sorry if my questions are unclear, i'm kind of a newb

BULK INSERT is not working correctly

I used bulk insert into SQL Server Management Studio 2008 R2, 10 words from a text UTF-8 file, into single column.
However, the words do not appear correctly, I get extra space in front of some words.
Note: None of the answers have solved my problem, so far. :(
SCREENSHOT OF THE PROBLEM
This issue may occur if you are not using the correct collation (language settings). You need to use the appropriate collation in order to display your data in the correct format.
See the link http://technet.microsoft.com/en-us/library/ms187582(v=sql.105).aspx for more details.
You can also try using a different row terminator:
bulk insert table_name
from 'filename.txt' WITH (ROWTERMINATOR='\n')
Look at this post How to write UTF-8 characters using bulk insert in SQL Server?
Quote: You can't. You should first use a N type data field, convert
your file to UTF-16 and then import it. The database does not support
UTF-8.
Original answers
look at the encoding of youre text file. Should be utf8. If not this could cause problems.
Open with notepad, file-> save as and choose encoding
After this try to import as a bulk
secondly, make sure the column datatype is nvarchar and not varchar. Also see here

What is the best SQL type to use for a large string variable?

Apologies for the rather basic question.
I have an error string that is built dynamically. The data in the string is passed by various third parties so I don't have any control, nor do I know the ultimate size of the string.
I have a transaction table that currently logs details and I want to include the string so that I can reference back to it if necessary.
2 questions:
How should I store it in the database?
Should I do anything else such as contrain the string in code?
I'm using Sql Server 2008 Web.
If you want to store non unicode text, you can use:
varchar(max) or nvarchar(max)
Maximum length is 2GB.
Other alternatives are:
binary or varbinary
Drawbacks: you can't search into these fields and index and order them
and the maximum size : 2GB.
There are TEXT and NTEXT, but they will be deprecated in the future,
so I don't suggest to use them.
They have the same drawbacks as binary.
So the best choice is one of varchar(max) or nvarchar(max).
You can use SQL Server nvarchar(MAX).
Check out this too.
Eventualy, you can enable and use a FILESTREAM feature of SQL Server 2008 (it's supported by WEB edition), and deal with extra large amount of data in sense of documents.
Of course, you need to be sure that you will use a benefit of this service.

Data Type Mapping

I need to store XML data to database(MS SQL Server). The data type defined in the column is text.
I need to know the the equalent datatype for text. I have tried with adLongVarChar but it does not works. Also I tried with adLongVarWChar(nText). But both are not working.
Need help.
Thanks.
In case your are using SQL Server 2005 or higher then you might prefer going for the XML data type. Read more of it here http://www.codeproject.com/KB/database/XMLdDataType.aspx
Also going forward avoid using ntext and text data types as they would be removed from future versions of SQL Server. Instead go for nvarchar(max) or varchar(max). Read on this here http://msdn.microsoft.com/en-us/library/ms187993.aspx
cheers
TSQL datatype for a string is varchar or nvarchar (unicode). To specify the length of the string, varchar(50).
Also note there is an XML datatype in SS 2008 (2005?).