MS SQL Server, indicating VARBINARY(MAX) field's datatype in VB.NET
So, I have this scenario where I use a VARBINARY(MAX) column, because I have no idea what is going to be put into it. All I know is that as of this point in time, the data will be one of many traditional data types(Integer, String, DateTime, etc.)
I also have another column that is meant to indicate the DataType so the .NET application can handle the data and validate input according开发者_JS百科ly.
Right now, for testing, I have a DataType table in my database that stores the "supported" datatypes for the VARBINARY column, and a foreign key linking to the column meant to indicate the DataType. This works perfectly, but it feels akward.
Given this scenario, what would some of you to to appropriately represent the type of data stored in the VARBINARY column?
How about a sql_variant
? See Using sql_variant Data.
Similar situation: In our EAV implementation, we created four separate columns in our "Value" table: a numeric, a short string (NVARCHAR(255)), a long string (NVARCHAR(MAX)) and a datetime. Then in the "Attribute" table we have a column indicating the datatype of the attribute. The separation helps us avoid awkward datatype conversions in our queries and allows us to improve our indexing by taking advantage of filtered indexes.
精彩评论