<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Undisciplined Bytes &#187; database</title>
	<atom:link href="http://www.undisciplinedbytes.com/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.undisciplinedbytes.com</link>
	<description>Web Application Development Tips, Tricks and Techniques</description>
	<lastBuildDate>Tue, 31 Jan 2012 09:07:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Entity Framework</title>
		<link>http://www.undisciplinedbytes.com/2012/01/entity-framework/</link>
		<comments>http://www.undisciplinedbytes.com/2012/01/entity-framework/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 09:07:24 +0000</pubDate>
		<dc:creator>Oliver Mezquita</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software engineering]]></category>

		<guid isPermaLink="false">http://www.undisciplinedbytes.com/?p=640</guid>
		<description><![CDATA[Entity framework is the new kid on the block on the ORM realm. It’s Microsoft new technology for data access, and although it didn’t receive very good comments on its first version, things have been greatly improved in its latest release. It now looks really interesting, with some features which surpass the most seasoned ORM [...]]]></description>
			<content:encoded><![CDATA[<p>Entity framework is the new kid on the block on the ORM realm. It’s Microsoft new technology for data access, and although it didn’t receive very good comments on its first version, things have been greatly improved in its latest release. It now looks really interesting, with some features which surpass the most seasoned ORM frameworks that have been in the game for years.</p>
<p>Here’s what Entity Framework (EF) has to offer:</p>
<p><span id="more-640"></span></p>
<ul>
<li>Using EF with the <strong>Model First approach</strong>, you design a schema of the model you want to implement, and EF generates a database and the code to implement it. Now, that’s what I call saving time! Using this approach, you can get going really really quick.</li>
<li>If you already have the code for your model, then EF can generate the database to store this model as well as the rest of the code handling persistance to this database, using the<strong> Code First approach</strong>.</li>
<li>In case you already have the database, EF can generate the code using the <strong>Database First approach</strong>.</li>
<li><strong>EF uses </strong><strong>Plain .Net objects (POCOs)</strong> with navigational properties to implement your model. Very easy stuff. The way EF lets you interact with the data once it’s retrieved from the DB is piece of cake (not the fact of data retrieval itself, that can get tricky).</li>
<li><strong>Automatic code generation</strong> with T4 templates. Once you have EF set up in your project, there’s a bunch of templates to generate a lot of code for you. That doesn’t mean you must use it, but it’s there for your convenience, in case you think some templates can help you. Me myself I use some of the T4 templates, but not all of them. There’s some things I actually prefer doing manually.</li>
<li><strong>Self-tracking entities</strong> will greatly simplify the process of implementing an over-the-wire scenario, in which you have different layers spanning across different systems and you have to serialize and de-serialize your entities. EF makes this really easy.</li>
<li><strong>Local caching</strong>, to speed up your data access.</li>
<li><strong>Lazy loading</strong>, which can improve overall application performance.</li>
<li>Support for <strong>LINQ</strong> (both coming from Microsoft, you would expect this, right?).</li>
<li><strong>Convention over configuration.</strong> The hottest trend in software development. You wouldn’t think EF would miss it, would you? When starting up a new project with EF, the only thing you need to configure are the database server and its name. Nothing else. All other things are taken care of for you. Of course, if you want more control over what EF is doing, you can tweak it to meet your criteria. But that isn’t something you have do right at the beginning. This way, you can be productive much faster.</li>
<li><strong>Support for the major databases</strong>: MS SQL Server (of course), Oracle, MySQL, PostgreSQL, etc…</li>
</ul>
<p>And last but not least:</p>
<ul>
<li>Coming from a big player in the industry like Microsoft, Entity Framework has great resources and a great community behind it. If you ever have a problem with EF, or want to tweak its behavior, chances are you’ll be finding what you need really fast. If you’re a seasoned developer, you’ll find this is one of the most important features of EF.</li>
</ul>
<p>If you haven’t tried it out yet, don’t wait any longer and <a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx">see for yourself what I’m talking about!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.undisciplinedbytes.com/2012/01/entity-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Persistance layer: object-relational mapping tools</title>
		<link>http://www.undisciplinedbytes.com/2011/12/persistence-layer-object-relational-mapping-tools/</link>
		<comments>http://www.undisciplinedbytes.com/2011/12/persistence-layer-object-relational-mapping-tools/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 10:36:16 +0000</pubDate>
		<dc:creator>Oliver Mezquita</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software engineering]]></category>

		<guid isPermaLink="false">http://www.undisciplinedbytes.com/?p=242</guid>
		<description><![CDATA[Nowadays it&#8217;s very usual to work with object-oriented programming and relational data bases. Relational data bases are all about tables, relations and groups. However, the object-oriented programming paradigm consists of objects, attributes and inter-object relationships. When these objects need to be stored using a relational data base, it&#8217;s very obvious that these two models of [...]]]></description>
			<content:encoded><![CDATA[<p>Nowadays it&#8217;s very usual to work with object-oriented programming and relational data bases. Relational data bases are all about tables, relations and groups. However, the object-oriented programming paradigm consists of objects, attributes and inter-object relationships. When these objects need to be stored using a relational data base, it&#8217;s very obvious that these two models of representing information are very different from each other. We need some kind of translation to transfer data from one to the other.</p>
<p>If we&#8217;re using objects in our application and we want to save them, we&#8217;ll probably use some data base system. We&#8217;ll most likely establish a connection to the data base, create a SQL sentence with the values of the object (or call some kind of stored procedure), and save them to some table. Easy enough, right? Well, this may seem trivial for a small object with 4 or 5 properties. Just consider an object not so small, with 40 or 50 properties. But&#8230; what happens with associations? And&#8230; what if the object itself contains some other objects? We&#8217;ll store them in the data base as well? All of them or just some? What will we do with foreign keys? We can see that, as the application gets more complex, this translation is not so trivial anymore&#8230; As a matter of fact, storing objects in the database can become a very usual source of headaches. There are some studies which state that <strong>up to 35% of code is dedicated to the role of translating data between the application and the data warehouse.</strong></p>
<p><span id="more-242"></span></p>
<p><strong> </strong></p>
<p>And this is where <strong><em>Object-Relational Mapping tools</em></strong> come into play. ORM tools applied to databases transform a DB register to a code object and vice-versa, allowing us to abstract away from writing code to directly access the database. This will speed up development and will allow us to follow the mantra of<strong> focusing on business functionalities, not on application plumbing</strong>.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">But, what exactly can an ORM tool help me with? Well, they usually do some things like:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- Handle object persistance (to a database, for example). You won&#8217;t have to write code for this. And remember, less code means less bugs and less headaches.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- Access different databases. Most of these tools support communicating with different database providers (Oracle, MS SQL Server, MySql, Postgre, etc.).</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- Cache. Many of these tools offer some way of caching objects in memory, resulting in much faster data access.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- Help with design. Some of these tools also provide some kind of wizar or graphical interface to aid in the design of the schema and/or database, which leads us to the following point:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- Create your database for you. If you have your data schema already modeled, some of these tools will not only handle how to get the data or how to write it. They can also create the database.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">So now that you&#8217;ve decided to use an ORM, take a look at the most popular ORM tools available for .NET:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- Linq to SQL: not really a full-blown ORM, but it does help with data access.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- NHibernate: I would say NHibernate is one of the most mature ORM projects in .NET, and one of the most used as well.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">- Entity Framework: Microsoft&#8217;s new kid on the block. Its first version didn&#8217;t receive very positive comments, but its latest release looks very good indeed.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">In the next post I&#8217;ll be covering Entity Framework a bit. Stay tuned!</div>
<p>But, what exactly can an ORM tool helps us with? Well, they usually do some things like:</p>
<ul>
<li><strong>Handle object persistance </strong>(to a database, for example). You won&#8217;t have to write code for this. And remember, less code means less bugs and less headaches.</li>
<li><strong>Access different databases</strong>. Most of these tools support communicating with different database providers (Oracle, MS SQL Server, MySql, Postgre, etc.).</li>
<li><strong>Cache</strong>. Many of these tools offer some way of caching objects in memory, resulting in much faster data access.</li>
<li><strong>Help with design</strong>. Some of these tools also provide some kind of wizard or graphical interface to aid in the design of the schema and/or database, which leads us to the following point:</li>
<li><strong>Create your database for you</strong>. If you have your data schema already modeled, some of these tools will not only handle how to get the data or how to write it. They can also create the database.</li>
</ul>
<p>You&#8217;re already convinced to use an ORM for your project, right? Good. Now take a look at the most popular ORM tools available for .NET:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx" target="_blank">Linq to SQL</a>: not really a full-blown ORM, but it does help with data access.</li>
<li><a href="http://nhforge.org/" target="_blank">NHibernate</a>: I would say NHibernate is one of the most mature ORM projects in .NET, and one of the most used as well.</li>
<li><a href="http://msdn.microsoft.com/en-us/data/aa937723.aspx" target="_blank">Entity Framework</a>: Microsoft&#8217;s new kid on the block. Its first version didn&#8217;t receive very positive comments, but its latest release looks very good indeed.</li>
<li><a href="http://www.llblgen.com/defaultgeneric.aspx" target="_blank">LLBLGen Pro</a>: very mature project, although it&#8217;s not the simplest of all.</li>
<li><a href="http://dataobjects.net/" target="_blank">DataObjects.Net</a>: quite new, but very promising. It already has a lot of interesting features. Definetely worth taking a look at.</li>
</ul>
<p>In the next post I&#8217;ll be covering Entity Framework a bit. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.undisciplinedbytes.com/2011/12/persistence-layer-object-relational-mapping-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which database to use for a personal project?</title>
		<link>http://www.undisciplinedbytes.com/2011/03/which-database-to-use-for-a-personal-project/</link>
		<comments>http://www.undisciplinedbytes.com/2011/03/which-database-to-use-for-a-personal-project/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 14:03:16 +0000</pubDate>
		<dc:creator>Oliver Mezquita</dc:creator>
				<category><![CDATA[backend]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[software engineering]]></category>

		<guid isPermaLink="false">http://www.undisciplinedbytes.com/?p=458</guid>
		<description><![CDATA[When starting a new project, the choice of which database to use usually boils down to the one the company usually uses. The systems that are usually considered are just Oracle and Microsoft’s SQL server (MS-SQL). There’s no doubt that big bucks companies have the resources to make the best-of-its-breed products, and almost no other [...]]]></description>
			<content:encoded><![CDATA[<p>When starting a new project, the choice of which database to use usually boils down to the one the company usually uses. The systems that are usually considered are just Oracle and Microsoft’s SQL server (MS-SQL). There’s no doubt that big bucks companies have the resources to make the best-of-its-breed products, and almost no other database system comes close to what Oracle and MS-SQL can offer in terms of quality, features, and highly skilled professionals around their products. Yes, all this is true, but there’s a price. And usually this price tag can only be afforded by a company, not by a sole individual.</p>
<p>So, what if I want to develop my own personal project and I require a RDBMS (<em>Relational DataBase Management System</em>)? Oracle and MS-SQL are out of the question because of their high cost. MS-SQL Express has great limitations, so, although it is free, we won’t be considering it for our purpose. Which is the best open source RDBMS?</p>
<p><span id="more-458"></span></p>
<p>Today’s most known open source RDBMS are MySQL and PostgreSQL. PostgreSQL is considered to beat MySQL in the features war. This used to be true some time ago, but it’s no longer the case anymore. 99% of the needs you will have with your RDBMS will be covered by both MySQL and PostgreSQL. Still, there’s many people who think that MySQL has improved a lot, but it’s just not PostgreSQL.</p>
<p>If you want to compare performance, fans of both systems will tell you their RDBMS is faster than the other one. On one hand, PostgreSQL has been recently paying attention to speed, and has been making its product faster and faster with every release. On the other hand, MySQL proponents say that, if configured properly, MySQL’s MyISAM tables are indeed lightweight and make for a faster database.</p>
<p>But probably, the most important thing to consider when choosing which RDBMS you should use, is which one is easier to use. I can tell you that previous Oracle experience will make you feel at home and comfortable with PostgreSQL. Still, the MySQL community seems to be much bigger than PostgreSQL’s, so, should you require some assistance when developing your project, if you’re using MySQL chances are that you will get quick help from them.</p>
<p>MySQL is licensed under the GNU GPL, but offers an alternative commercial license for those who don’t want to be restricted by that license. PostgreSQL uses the BSD license, which stipulates that the credits have to be maintained, but beyond that you can do whatever you want with it.</p>
<p>But, after all, it just all comes down to personal tastes. Just choose whatever you like and whichever you think might fit your needs better. What might be the best for one person, might be a bad choice for another.</p>
<p>Check these links for more info:</p>
<ul>
<li><a href="http://www.devx.com/dbzone/Article/29480" target="_blank">Open Source Database Feature Comparison Matrix</a></li>
<li><a href="http://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems" target="_blank">Comparison of RDBMS</a></li>
</ul>


<h4>Related posts:</h4><p><ol><li><a href='http://www.undisciplinedbytes.com/2010/01/sluggish-database-view-materialize-it/' rel='bookmark' title='Permanent Link: Sluggish database view? Materialize it!'>Sluggish database view? Materialize it!</a></li>
<li><a href='http://www.undisciplinedbytes.com/2012/01/entity-framework/' rel='bookmark' title='Permanent Link: Entity Framework'>Entity Framework</a></li>
<li><a href='http://www.undisciplinedbytes.com/2011/12/persistence-layer-object-relational-mapping-tools/' rel='bookmark' title='Permanent Link: Persistance layer: object-relational mapping tools'>Persistance layer: object-relational mapping tools</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.undisciplinedbytes.com/2011/03/which-database-to-use-for-a-personal-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sluggish database view? Materialize it!</title>
		<link>http://www.undisciplinedbytes.com/2010/01/sluggish-database-view-materialize-it/</link>
		<comments>http://www.undisciplinedbytes.com/2010/01/sluggish-database-view-materialize-it/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 14:59:29 +0000</pubDate>
		<dc:creator>Oliver Mezquita</dc:creator>
				<category><![CDATA[backend]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.undisciplinedbytes.com/2010/01/sluggish-database-view-materialize-it/</guid>
		<description><![CDATA[The other day we were having some slow database view at our project. It was the main view of the new module we were developing, and it was slowing down the whole application to an unacceptable point. It was a rather complex view and could not be optimized much more. So, what was the solution [...]]]></description>
			<content:encoded><![CDATA[<p>The other day we were having some slow database view at our project. It was the main view of the new module we were developing, and it was slowing down the whole application to an unacceptable point. It was a rather complex view and could not be optimized much more. So, what was the solution we adopted? We materialized the view.</p>
<p>Regular views store just the SQL script needed to retrieve the data, and every time they are consulted the stored SQL query is executed. However, materialized views not only store the script, but the retrieved records as well, making it much faster.</p>
<p><span id="more-254"></span></p>
<p>As with regular views, the SQL script defines which data is to be retrieved. However, with materialized views this script is executed when the view is first created, and the result is physically stored in a real table. From then on, when the materialized view is accessed, the <a href="http://en.wikipedia.org/wiki/Database_management_system" target="_blank">DBMS</a> transforms the SQL sentence targeting this table instead of the more expensive procedure of actually querying all elements involved in the SQL sentence.This table can be defined with the same storage parameters used for regular tables (tablespace, etc.). Indexes can be used for materialized views as well, improving the performance even more.</p>
<p>Obviously, the greater the number of tables used, the more benefits we’ll get by using a materialized view. In our project, we were accessing 15 tables: we cut the execution time from 4 seconds to 100 ms by implementing a materialized view… this means <strong>that execution was 40 times faster!!!</strong> Now, that’s what I call optimization!</p>
<p>However, when designing a materialized view you need to keep in mind that it’s actually going to become a table with static data… and you need to specify when and how that data is going to be updated. Not taking this into account might lead the application to display outdated or incorrect data. This means that <strong>we need to evaluate the benefits and drawbacks we’ll get by using a materialized view: it might as well turn out that it slows down the whole system. </strong>So I encourage you to do some design and testing before actually deploying the view into production environment.</p>
<h4>How to build a Materialized view in Oracle</h4>
<p>This is the command used to create materialized views:</p>
<pre class="brush:sql">CREATE MATERIALIZED VIEW materialized_view_name
 [TABLESPACE ts_name]
 [PARALELL (DEGREE n)]
 [BUILD {INMEDIATE|DEFERRED}]
 [REFRESH {FAST|COMPLETE|FORCE|NEVER|ON COMMIT}]
 [{ENABLE|DISABLE} QUERY REWRITE]
AS SELECT ... FROM ... WHERE ...</pre>
<p><strong>The <em>Build</em> parameter</strong></p>
<p>If you choose the <code>BUILD INMEDIATE</code> option, the table associated with the materialized view will be populated with data at creation time. On the contrary, if you’d rather have the table populated in the moment when the first access to the view is performed, then use the <code>BUILD DEFERRED</code> option.</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>The <em>Refresh</em> parameter</strong></p>
<p>This option indicates the mechanism Oracle will use to update the table representing the materialized view. There quite a few options here, and I would say it’s one of the most important considerations when building a materialized view. I will write a new article explaining the different updating approaches we can use to implement these views.</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>The <em>Query Rewrite</em> parameter</strong></p>
<p>The <code>ENABLE/DISABLE QUERY REWRITE</code> option indicates whether the Oracle optimizer is allowed to rewrite SQL sentences in a way in which the materialized view will be used in the execution phase instead of the base tables included in the original SQL sentence. This is a rather complex subject, and I will dedicate a post dealing with it.</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<h4>Other DBMS</h4>
<p>This article focused on Oracle’s Materialized Views. But most DBMS implement some kind of view optimization these days. In case you’re using some other DBMS, you might be interested in searching for:</p>
<ul>
<li>Microsoft SQL Server: Indexed views.</li>
<li>DB2: Materialized query table.</li>
<li>Some other DBMS (for example MySQL and PostgreSQL) don’t have such a feature, but you can implement your own manually using triggers.</li>
</ul>
<h4>Further reading</h4>
<ul>
<li><a href="http://download.oracle.com/docs/cd/B10500_01/server.920/a96567/repmview.htm" target="_blank">Oracle Materialized View Concepts and Architecture</a></li>
<li><a href="http://technet.microsoft.com/en-us/library/cc917715.aspx" target="_blank">Microsoft SQL Server 2005 Indexed views</a></li>
<li><a href="http://publib.boulder.ibm.com/infocenter/db2luw/v8//index.jsp?topic=/com.ibm.db2.udb.doc/core/c0009318.htm" target="_blank">DB2 Materialized query table</a></li>
</ul>


<h4>Related posts:</h4><p><ol><li><a href='http://www.undisciplinedbytes.com/2011/03/which-database-to-use-for-a-personal-project/' rel='bookmark' title='Permanent Link: Which database to use for a personal project?'>Which database to use for a personal project?</a></li>
<li><a href='http://www.undisciplinedbytes.com/2011/12/persistence-layer-object-relational-mapping-tools/' rel='bookmark' title='Permanent Link: Persistance layer: object-relational mapping tools'>Persistance layer: object-relational mapping tools</a></li>
<li><a href='http://www.undisciplinedbytes.com/2012/01/entity-framework/' rel='bookmark' title='Permanent Link: Entity Framework'>Entity Framework</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.undisciplinedbytes.com/2010/01/sluggish-database-view-materialize-it/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

