Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


EAV or XML


EAV or XML

Author
Message
N_Muller
N_Muller
SSC-Enthusiastic
SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)

Group: General Forum Members
Points: 133 Visits: 404
I have a set of tables in database where I cannot change its structure. I need to create extensions to the tables by adding new attributes (columns). The list of columns and their data types is determined dynamically by the applications that use the database.

I thought of using an EAV approach for the extensions, or create a table with a XML column to store the variable extensions and maintain a relational structure. Another possibility is a hybrid approach where I would create an EAV for the metadata only, and use the XML for storing the data.

I would appreciate if someone could comments on the options or enlighten me with different ideas.
Elliott Whitlow
Elliott Whitlow
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6208 Visits: 5314
I have been spending a lot of time playing with the XML data type in SQL lately. And I have been largely UNDERwhelmed with the performance. I would POC it both ways to see how it performs.

CEWII
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17524 Visits: 32251
I'm with Elliot. I've done lots of programming in and around XML on SQL Server. It's functional. But it's not terribly fast. If you're just talking, writing and reading this stuff in and out of the database as XML and then all parsing is done at the client side, yeah, that'll work. But if you're talking filtering and querying the XML, I think you'll be digging a pretty dark hole for yourself.

EAV structures can work, although they're hard to set up. I saw a discussion on it recently somewhere (or maybe I was involved in one at an event, I don't remember) where people were able to get EAV to work nicely. But it takes a bit of effort and some careful coding. Take your time and don't do crazy shortcuts around how SQL Server stores and accesses data because those almost never work out well.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
N_Muller
N_Muller
SSC-Enthusiastic
SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)

Group: General Forum Members
Points: 133 Visits: 404
Grant, would it be possible to post a link to the event name or the document you saw, in case it is public domain? Thanks
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17524 Visits: 32251
I would if I remembered it. It might have been a conversation I had at SQL Saturday DC. I just don't recall, sorry.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44766 Visits: 39845
N_Muller (12/12/2013)
I have a set of tables in database where I cannot change its structure. I need to create extensions to the tables by adding new attributes (columns). The list of columns and their data types is determined dynamically by the applications that use the database.

I thought of using an EAV approach for the extensions, or create a table with a XML column to store the variable extensions and maintain a relational structure. Another possibility is a hybrid approach where I would create an EAV for the metadata only, and use the XML for storing the data.

I would appreciate if someone could comments on the options or enlighten me with different ideas.


If the columns being added are not added by the whim of an end user, consider multiple "sister tables" in a star schema. Although that can add a bit o' complexity to code, it allows real data-typing of the new columns, can be fast as the wind, and also easily allows for DRI.

If you decide to go the EAV route and you have no "blob" data, read up on the SQL_VARIANT datatype which allows for some semblance of metadata preservation (I use it for column-level Audit tables).

I share Elliott's and Grant's observations on XML except I'll go several steps further. I feel that it's a grossly overused, over advertised, resource intensive, difficult to maintain, pipe clogging, bloated method that should be avoided in a database at any and all costs because it's worth avoiding.

Heh... strong letter to follow. :-P

--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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
N_Muller
N_Muller
SSC-Enthusiastic
SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)

Group: General Forum Members
Points: 133 Visits: 404
Thanks, everyone. In the end I'm using the EAV for metadata only. I created a stored procedure that runs every time a new attribute is created (trigger) to generate an alter view that returns all columns of the main table and the additional columns in the metadata EAV.
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