Mysql Naming Convention

Mark Hobson red5consulting at gmail.com
Tue Apr 18 18:34:34 MDT 2006


Just as a followup...

Technically, the database should be abstracted from the code.  Now that
doesn't mean that the code can't be named based on the database, but the
database layer should be abstracted enough so that it can be replaced with a
different flavor of database or a different engine altogether...like xml.

Taking that into account, if there was an xml file, would, say of clients
and notes, would you structure it like this:

<xml>
	<client>
		<client>
			<name>
			<note>
				<note>
					<content/>
					<note_id/>
				</note>
				<note>
					<content/>
					<note_id/>
				</note>
			</note>
		</client>
		<client>
			<name>
			<note>
				<note>
					<content/>
					<note_id/>
				</note>
				<note>
					<content/>
					<note_id/>
				</note>
			</note>
		</client>
	</client>
</xml> 

Definitely not!!, you would wrap the client nodes and the note nodes within
<clients></clients> tags and <notes></notes> tags respectively.  Thus, a
client has multiple notes, all of which are wrapped in a container tag.
Likewise, a clients table contains multiple clients, all of which are
"wrapped" in a container table called clients.  

Mark

-----Original Message-----
From: plug-bounces at plug.org [mailto:plug-bounces at plug.org] On Behalf Of Mark
Hobson
Sent: Tuesday, April 18, 2006 4:22 PM
To: plug at plug.org
Subject: RE: Mysql Naming Convention

Plural is the right way.  SQL was designed to be a natural language (thus
the select col from tablename where...)

Thus, a class represents a row in a table...a single row, whereas the table
represents a collection of rows (plural).  Therefore, the table name is
plural, the class name is singular.

If you are using a framework, it should have a small function to convert
from plural to singular.  You'll have to anyway, since at some point, you'll
need to have a plural word somewhere (i.e. "List of Clients" for the title
of a page, that queries the clients table).  

MySQL even has built in functions that are plural:

Show databases
Show tables

Mark

-----Original Message-----
From: kirk [mailto:kirk at emstraffic.com]
Sent: Tuesday, April 18, 2006 4:17 PM
To: mark at emstraffic.com
Subject: Fw: Mysql Naming Convention


----- Original Message -----
From: "Louis Zirkel" <lzirkel at cendev.com>
To: "Provo Linux Users Group Mailing List" <plug at plug.org>
Sent: Tuesday, April 18, 2006 4:12 PM
Subject: Re: Mysql Naming Convention


Gregory Hill wrote:

> But, there is no rule or standard in this regard.

Someone else said it as well but I personally think that since there is
no true standard that consistency is the most important thing.  I think
the best thing would be to have a set of "engineering standards" for
naming conventions, be it in source code or sql code, or anything along
those lines for that matter.

-- 
Louis Zirkel / lzirkel at cendev.com
Developer/SysAdmin/DBA

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/


/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/




More information about the PLUG mailing list