Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

sql_variant Expand / Collapse
Author
Message
Posted Friday, March 13, 2009 10:31 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 35,769, Visits: 32,437
Steve Mong (3/13/2009)
Certain classes of apps can't anticipate the data types they'll be required to store, manipulate, etc.

Master Data Management apps have always been prominent examples (wherein Oracle's product uses its own version of sql_variant). Microsoft's CRM product is another case in point...they elected to go with XML 'property bags', but that has its own strengths and weaknesses. The challenge is basically the same, and variants offered the way out.

Further, I believe this challenge is shaping up to be a central modeling issue for the future of IT: highly configurable SaaS offerings. In a nutshell, experience with variant data types will grow to be a necessity for archs, modelers and developers.


Heh... yep... just like the folks that use VARCHAR(MAX) for everything... ;)


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #675774
Posted Saturday, March 14, 2009 5:06 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, November 4, 2012 12:23 PM
Points: 1,893, Visits: 3,932
Hi

I'm using sql_variant alike Jeff stated for logging. I've got a usp_Log like this:

CREATE PROCEDURE dbo.usp_Log 
@msg VARCHAR(4000),
@p1 SQL_VARIANT = NULL,
@p2 SQL_VARIANT = NULL,
@p3 SQL_VARIANT = NULL,
@p4 SQL_VARIANT = NULL,
@p5 SQL_VARIANT = NULL,
@p6 SQL_VARIANT = NULL,
@p7 SQL_VARIANT = NULL,
@p8 SQL_VARIANT = NULL,
@p9 SQL_VARIANT = NULL
AS
-- ...

So I can specify 0 to 9 place holders (%1 to %9) to be replaced with any information.

Greets
Flo



The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Post #675839
Posted Saturday, March 14, 2009 8:38 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 7:27 AM
Points: 35,769, Visits: 32,437
Florian Reischl (3/14/2009)
Hi

I'm using sql_variant alike Jeff stated for logging. I've got a usp_Log like this:

CREATE PROCEDURE dbo.usp_Log 
@msg VARCHAR(4000),
@p1 SQL_VARIANT = NULL,
@p2 SQL_VARIANT = NULL,
@p3 SQL_VARIANT = NULL,
@p4 SQL_VARIANT = NULL,
@p5 SQL_VARIANT = NULL,
@p6 SQL_VARIANT = NULL,
@p7 SQL_VARIANT = NULL,
@p8 SQL_VARIANT = NULL,
@p9 SQL_VARIANT = NULL
AS
-- ...

So I can specify 0 to 9 place holders (%1 to %9) to be replaced with any information.

Greets
Flo


You've probably hit on one of the only places I've ever used SQL_Variant... logging in EAV's/NVP's.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #675894
Posted Monday, August 18, 2014 7:01 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 1:23 PM
Points: 157, Visits: 981
I think the main reason for sql_variants has been missed here and are therefore being bashed unfairly. Their purpose is to allow different data types to be stored in a column so each row potentially has a different data type for that column. This is useful for allowing end users to decide what to store in "their" column on a per row basis. Think of this as intentional late binding...which always adds flexibility and power at the cost of performance. The SQL_VARIANT_PROPERTY function will tell you the type a user has used for a given row.
Post #1604428
Posted Friday, October 31, 2014 6:40 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 6:42 PM
Points: 459, Visits: 1,065
The author of this article makes use of the sql variant. When capturing configuration baseline data one column is the configuration name and another the value. Of course the configurations are not all the same data type.

http://www.sqlservercentral.com/articles/baselines/94656/

I think it is a valid use.
Post #1630278
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse