<?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>Search results matching tags 'Database Design' and 'code'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Database+Design,code&amp;orTags=0</link><description>Search results matching tags 'Database Design' and 'code'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>What's in a name?</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2010/08/22/what-s-in-a-name.aspx</link><pubDate>Sun, 22 Aug 2010 19:12:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:28149</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;In a lot of my projects, the issue of naming/coding conventions comes up.&amp;nbsp; I am a big fan of PascalCase/plural for tables and views (e.g. dbo.CustomerAddresses, dbo.OrderDetails), PascalCase for column names (e.g. FirstName, HomePhone); and for stored procedures, I am partial to the Entity_Action naming convention (e.g. dbo.Customer_Create, dbo.Customer_Update).&amp;nbsp; I know some like to separate out their words with underscores, but with the exception of stored procedures, I find this tedious.&amp;nbsp; &lt;/p&gt;

&lt;p&gt;One of the stickier points in several cases has been how to case short suffixes, such as the ID in CustomerID.&amp;nbsp; Let's go back to what the ID is; an identifier.&amp;nbsp; I often liken it to an identification card, which usually contains either a visible or a bar-coded identifier of some sort (SSN, driver's license #, etc).&amp;nbsp; While sometimes this card is called an I.D. and sometimes an ID, I have yet to see it called an Id or an id.&lt;/p&gt;

&lt;p style="margin-left:40px;"&gt;&lt;img src="http://sqlblog.com/files/folders/28148/download.aspx" width="360" border="1" height="280"&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;For short suffixes that are actually acronyms, I prefer all upper-case.&amp;nbsp; Most developers I've come across seem to like to lower-case the remainder of the acronym.&amp;nbsp; And in some cases they have to; e.g. in JavaScript you refer to element.innerHtml; if you try element.innerHTML you get an error message.&amp;nbsp; I can still tell what Html and Xml are when they aren't in upper-case, but it can be cumbersome to read that way, particularly with the Id / ID suffix.&amp;nbsp; Because often "CustomerId" can look like "Customerld" - the difference is only slightly more clear in a fixed width, code-ish font:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;CustomerId vs. Customerld&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Among other things, using an upper-case ID ensures that everyone knows we aren't talking about the customer's "pleasure principle" (&lt;a href="http://en.wikipedia.org/wiki/Id,_ego,_and_super-ego" title="http://en.wikipedia.org/wiki/Id,_ego,_and_super-ego" target="_blank"&gt;according to Freud&lt;/a&gt;).&amp;nbsp; And isn't this easier to read?&amp;nbsp; &lt;br&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;CustomerID&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;


&lt;p&gt;The "I dee" part rings out much better for me when the acronym is upper case.&amp;nbsp; And when I find queries written by others where they have used their convention, I always re-write to conform to my convention.&amp;nbsp; And while it is as weak an argument as writing standards-compliant code for fear that you will ever port to a different RDBMS, I find it hard to justify leaving code as is when it will fail if we ever have to use a case sensitive collation.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Even when I will always name the database entities in this way, if you want to call it CustomerId in the application code, feel free.&amp;nbsp; Just be consistent.&amp;nbsp; And don't expect me to leave it that way if you hand control of the code over to me.&lt;/p&gt;&lt;p&gt;What are your thoughts?&amp;nbsp; Are you a proponent of CustomerId?&amp;nbsp; In the application code only, or in both the app and the database?&amp;nbsp; If so, why?&lt;br&gt;&lt;/p&gt;</description></item></channel></rss>