SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sql_variant


sql_variant

Author
Message
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85545 Visits: 41082
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... Wink

--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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Florian Reischl
Florian Reischl
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3469 Visits: 3934
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
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85545 Visits: 41082
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Bill Talada
Bill Talada
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1159 Visits: 1996
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.
MMartin1
MMartin1
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2747 Visits: 2031
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.

----------------------------------------------------
How to post forum questions to get the best help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search