Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing unknown datatype in MS SQL Server Database

Does any one has an idea of whats the best practice to store an unknown data type in a table. Basically I would need to store types like bit, smallint, int, real and nvarchar in the same "value" column, for later interpretation by a .NET application.

I was trying to achieve the best possible solution not to compromise the performance or growth of the database.

Any suggestions?

Thanks in advance!

like image 366
Guilherme Duarte Avatar asked Oct 07 '10 14:10

Guilherme Duarte


People also ask

How can I store alphanumeric data in SQL?

You can use these SQL data types to store alphanumeric data: CHAR and NCHAR data types store fixed-length character literals. VARCHAR2 and NVARCHAR2 data types store variable-length character literals. NCHAR and NVARCHAR2 data types store Unicode character data only.

What is a special value in SQL that represents missing or unknown data?

Databases use a special value called NULL to represent missing information.

What is unknown value in SQL?

NULL indicates that the value is unknown. A null value is different from an empty or zero value. No two null values are equal.


1 Answers

Varchar(max) is probably the easiest way to do this.

sql_variant was designed for this purpose so you could use it, but read the Books Online entry to ensure it's going to do what you want.

http://msdn.microsoft.com/en-us/library/ms181071.aspx

like image 105
Paul Spangle Avatar answered Sep 23 '22 15:09

Paul Spangle