<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Arnie Rowland: Ramblings of a Harried Technogeek : EAV, SQLServer</title><link>http://sqlblog.com/blogs/arnie_rowland/archive/tags/EAV/SQLServer/default.aspx</link><description>Tags: EAV, SQLServer</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Through the Looking Glass: Elegant -or Not?</title><link>http://sqlblog.com/blogs/arnie_rowland/archive/2008/10/03/through-the-looking-glass-elegant-or-not.aspx</link><pubDate>Fri, 03 Oct 2008 06:19:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:9203</guid><dc:creator>ArnieRowland</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/arnie_rowland/comments/9203.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/arnie_rowland/commentrss.aspx?PostID=9203</wfw:commentRss><description>&lt;P style="MARGIN:0in 0in 10pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';"&gt;&lt;FONT face=Calibri&gt;&lt;STRONG&gt;SQL Server as an EAV Database -Good Idea?&lt;/STRONG&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';"&gt;&lt;FONT face=Calibri&gt;It seems like I am getting more and more inquires from potential clients asking for help solving performance related issues with what, after some investigation, is using SQL Server as an EAV database. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';"&gt;&lt;FONT face=Calibri&gt;First, for those unfamiliar with the concept, an Entity-Attribute-Value (EAV) database seems disarmingly simple and seductive to many developers. In its simplest form, an EAV database requires only one table, and that table has only&amp;nbsp;four columns: an Identifier, the Entity, the Attribute, and the Value of the Attribute. The entity might be a Customer, the Attribute ‘&lt;I style="mso-bidi-font-style:normal;"&gt;Customer Name&lt;/I&gt;’, and the Value would be the actual customer's name. The same table could also contain Products, or Invoices, or Employees, etc. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';"&gt;&lt;FONT face=Calibri&gt;The beauty of the design is that the developer is free from ever having to consider a table schema. Need another column, that’s just another Attribute/Value pair. Need another table -just a different type of entity. Add as many new entities, or new columns as is desired. One never has to negotiate with a DBA again. There is never a need to have to write that &lt;I style="mso-bidi-font-style:normal;"&gt;messy&lt;/I&gt; and sometimes problematic ALTER TABLE code again. Wonderful concept if you have to distribute changes to the data model in situations where the user (or application) does not have permissions to &lt;I style="mso-bidi-font-style:normal;"&gt;muck around&lt;/I&gt; with the database, the schema, and all of that DBA&amp;nbsp;&lt;I style="mso-bidi-font-style:normal;"&gt;stuff&lt;/I&gt;. There is only one data model, and it is only one table that has four columns. What could go wrong with that?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';"&gt;&lt;FONT face=Calibri&gt;And, of course, it is possible to select the ATTRIBUTE/VALUE pairs for an ENTITY (or group of entities) and PIVOT the data to simulate a table. It seems simple enough –doesn’t it? (If you want more information, just search for &lt;I style="mso-bidi-font-style:normal;"&gt;Common Table&lt;/I&gt;, &lt;I style="mso-bidi-font-style:normal;"&gt;EAV Database&lt;/I&gt;, &lt;I style="mso-bidi-font-style:normal;"&gt;Table of Tables&lt;/I&gt;, etc.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;mso-fareast-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';"&gt;&lt;FONT face=Calibri&gt;In fact, the beauty is in the elegance of the model. Frankly, before the advent of SPARSE columns, you could save a lot of storage when there was a long list of potential attributes (columns), and most entities would only use a small portion of the potential attributes. And it works wonderfully for many situations: obviously, property ‘bags’, somewhat small and static tables –you know, the types of data that will be used to populate various UI controls, or be used for data validation, or internal processes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;FONT face=Calibri&gt;I’m not going to address the issues of the increasing complex code required to pivot the &lt;I style="mso-bidi-font-style:normal;"&gt;faux&lt;/I&gt; tables –I’ll leave that to later discussions. Today, I’m interested in performance issues. One client has an EAV database that is approaching two billion rows in that single table –and the performance is starting to become quite troublesome. They really didn’t like my even broaching the subject of a data model redesign –too much ego involved in this &lt;I style="mso-bidi-font-style:normal;"&gt;elegant&lt;/I&gt; design.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;FONT face=Calibri&gt;I’m interested in your experiences, cautions, and concerns surrounding performance issues of using SQL Server as an EAV database. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;FONT face=Calibri&gt;So tell me, when does something that is elegant from one perspective become burdensome and inelegant from another?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 10pt;" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=9203" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/arnie_rowland/archive/tags/Developer/default.aspx">Developer</category><category domain="http://sqlblog.com/blogs/arnie_rowland/archive/tags/EAV/default.aspx">EAV</category><category domain="http://sqlblog.com/blogs/arnie_rowland/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/arnie_rowland/archive/tags/SQLServer/default.aspx">SQLServer</category></item></channel></rss>