I see a lot of people using different naming conversions, from company to company, for their database objects to their programming language variables, functions and and...
What do you prefer?
E.g. NameOfSomething / Name_Of_Something / name_of_something / etc
How do you name your database objects - tables, stored proc, views, columns, etc?
Do you start with a prefix, and group them accordingly
E.g. (for stored procedures) sp_Procuct_UpdateSomething/ sp_Customer_UpdateSomething
First off, when it comes to naming stored procedures,
DO NOT name your stored procedure: sp_whatever_my_stored_procedure
The "sp_" in front of the name makes SQL Server check dbo.master if the stored procedure is there first, then if it fails to find it, checks your database. This is something internal to SQL Server and might have been changed in the 2005/2008/2010 versions.
As for my naming convention: proc_[module]_[function][Description]
So I'll have:
proc_Customer_addCustomer
proc_Customer_editCustomer
proc_Basket_addItem
proc_Basket_deleteItem
etc. Just because adding a basket item is a "customer" function for example, it doesn't fall under the module of the "Basket" functionality, so you'll never see me do: proc_Customer_addBasketItem
Doing this automatically groups all of my modules together in nice alphabetical format and everyone working on the project can immediately see what the function of the procedure and where it should originate from. This ties in with my naming convention for my directories as well when working with web applications:
root/modules/basket/basket_addItem.asp
root/modules/basket/basket_editItem.asp
root/modules/basket/js/basket.js
etc. When working with Windows Applications I tend to:
frmMainUI
frmBasket
frmCustomer_editProfile etc
Internally (speaking of code specific)
When working with Boolean's, my naming convention for example is: blnDescriptive_Name (real world example: blnCustomer_IsActive). Just touching on Boolean usage quickly. Always try to be positive (as you should be in life all the time sonny boy). If you do:
"If NOT blnCustomer_Active Then"
All the time, you should reconsider your approach. By naming your variable "blnCustomer_IsActive" it makes the code quite enjoyable to read when looking at it from an outside perspective. "If this customer is active then do this bit of code"
Going back to SQL Server, since I started with SQL Server I figured I'll end with it again. Absentminded as I am.
When dealing with tables, I make it hard to guess from an outside perspective. This is just to **** with someone trying to guess my table names IF they find a way to inject SQL into the system (which you can't always be sure of, especially when you're programming in a multi-programmer environment for one project). I'll call my table something like, cms_tblCustomer (nb, I never use plurals in my naming convention. Or if I do, I always use it throughout the database. I guess I have OCD when it comes to this)
I never use Views because I find them clunky and abused by programmers who are too lazy to code properly and have no insight into a growing database and what an unchecked view could do to the server's performance.
Columns are pretty easy. I almost never use "_" in the naming convention and always capitalize "ID". So:
cms_tblCustomer would contain CustomerID,FirstName,Surname,DOB etc
I always add the following to any and all my tables, you might want to do this too!
Active (boolean, default 'true')
UserIDLastModified (integer, required)
LastModifiedDate (datetime, default null)
DateCreated (datetime, default getdate())
This should leave a basic paper trail of who did what in your database. I have a more advanced auditing system I wrote a couple of years back based on triggers which keeps the actual changes to every column in every table including which user did what, and it's proven several times that if someone ****s up, notices the ****-up, goes back and changes it and then when their manager queries this because it filtered through to the client somehow (or if it's the client itself that did this) and then conveniently blames IT, I just pull up the logs and go "Ah I see, you authorized this item to be published in the catalog at 11:41:23.022 AM today, then you changed it back 10 minutes ago. I can see why people bought this special, as the price was entirely wrong."
Then they're really quick to STFU. And when the manager bitches about the system "because it can't be his/her employees" I just pull another log and go "And at 11:49:44.052
you approved the changes to this item and it subsequently went live"
Anyway. Hope you n00bs learned something
And yes i know I predominantly talk "VB", it's easier to understand for most people starting out and I wrote this in hopes someone else might find this useful.