Important alert: (current site time 7/15/2013 7:19:52 PM EDT)
 

article

Organise your SQL!

Email
Submitted on: 12/11/2000 9:01:16 AM
By: Tony Cheetham  
Level: Beginner
User Rating: By 6 Users
Compatibility: SQL Server 7.0, SQL Server 6.5 and earlier
Views: 16390
(About the author)
 
     Having trouble organising your SQL tables? Do you have to keep a hard copy of all your SQL tables because you cant remember column names? This article will help you.


 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				Im sure weve all done it. Started to write a select statement and then had to alt+tab back to enterprise manager to find out the column name. Well, if your still starting out in SQL and having trouble organizing things, this method is for you. And its all logical, so recalling table and column names should be a breeze.

Ok, to start of with were going to make a small list of all our tables in alphabetical order, leaving out any link tables you may need. For my example Im using a small discussion forum database.

Tables.
-------
Forum
Msg
User
Topic

Now, next to all of these create a 2 character reference code for each table, you can use three if it makes much more sense.

Tables.
-------
Forum -=- FR
Msg -=- MS
User -=- US
Topic -=- TP

Ok, now we have those, we can make out link tables. We need to link the users to topics, and it makes more sense to link the ID's through a link table, so we combine the two codes.

Link Tables.
------------
User & Topic tables -=- US_TP
Now we have all our table names, go ahead and create them all, using there long names(i.e. 'user' table). Once there made, we can start entering fields, I wont go through them all, just one example.

'User' Table Columns.
--------------------
US_ID
US_USERNAME
US_PASSWORD

Now as you can see we use our two character code as a suffix to each column. This doesnt do much in the 'user' table, but take a look at the topic table.

'topic' Table Columns(shortened).
----------------------
TP_ID
TP_TITLE
TP_TIMESTAMP
US_ID

You can see weve taken the column name from the 'user' table, and just used it in the topic table. So if you need to remember of the top of your head what the link from the topic table is to the use table, its as simple as thinking, user table is US, so the link column is US_ID. This works for near enough any simple database, and works on link tables to, for example,

'topic' And 'user' Link Table.
------------------------------
Table name -=- US_TP
US_TP_ID
US_TP_EMail
US_ID
TP_ID

You can easily figure out where any of those columns link, using there code. Ive attached a quick mock up of the database Ive discussed here in JPG format. As you can see it works well in diagram mode as well!


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
5/26/2006 10:29:55 PMRichard Henerlau

Basicly, this is an adaptation of Leszynski/Reddick Naming conventions commonly used in Access and Visual BASIC
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.