Professional Documents
Culture Documents
www.techrepublic.com
Page 1
www.techrepublic.com
Page 2
www.techrepublic.com
Watch your naming conventions between table names, report names, and query names. It can get very confusing very fast as to what you are working with and where its at. If you insist on naming these components identically, at least identify them with table, query, or report at the beginning of the name of the object. rrydenm With Microsoft Access, it is acceptable to use qry, rpt, tbl, and mod to identify objects (e.g., tbl_Employees). When I deal with SQL Server (or Oracle) I still use tbl to reference tables, but I use sp_company (currently sp_feft_) for stored procedures, because I sometimes keep copies of special ones Ive written if I've found a clever way to do something, and v_ for views. When we implement SQL Server 2000, I will use udf_ (or something similar) for the functions I write. Timothy J. Bruce
3. Plan ahead
Back in the early 1980s, when working with an asset ledger system and a System 38, I had an opportunity to make all the date fields so they would handle the year 2000 problem without a lot of extra work. Many people said that I should forget about working on the problem because it would take too much effort to deal with it. (This was long before it became known as the Y2K problem.) I bit the bullet back then, planning ahead. It took a couple of weeks to make all the changes in the set of programs. But because of that preplanning, Y2K mods should have been minimal. (The last I heard, the programs were going strong on an AS/400 in 1995. The only problem with them at that time was the removal of comments from the source code.) generalist
www.techrepublic.com
first name from middle name, we should try to sell them on it. We all have had those "if only Id done it this way" moments. dhattrem
Page 4
www.techrepublic.com
Page 5
www.techrepublic.com
Page 6
www.techrepublic.com
workflow in the database as well. It takes a little more effort up front, but if those processes are data-driven rather than hard-coded in the UI, policy changes and maintenance are much easier. In fact, if the process is data-driven, you can give much of that responsibility back to the users and let them maintain their own workflow processes and change them without coming to you. tduvall
Page 7
www.techrepublic.com
Page 8
www.techrepublic.com
ADDRESS can be Site, Location, Home, Work, Client, Vendor, Corporate, FieldOffice, etc. By using generic abstract terms to identify classes of "things," you gain the greatest flexibility in relating the data to meet business needs while at the same time reducing the amount of redundant storage you need for the data. teburlew
11. Remember that there may be users outside the United States
When designing a database that will be used on the Web or other international stage, remember that most countries have a different format for fields like ZIP/post codesand some, like New Zealand, do not use these codes. billh
Page 9
www.techrepublic.com
(include the middle initial field if it's appropriate); then concatenate the fields later in your queries. klempan Klempan isn't the only one to notice widespread use of a single name field. You have several options for making it user-friendly. One of my favorites is to simply create a computed column in the same table that will automatically concatenate the normalized fields yet change when the data changes. However, this can get tricky when using modeling software. A view is also a great way to insulate users/developers from the tedium of concatenating fields. damon
16. Watch out for mixed-case object names and special characters
Something that has caused me grief in the past is when an existing database I had to work with had mixed-case object names (CustomerData). The problem I ran into was porting from Access to Oracle. I didn't want mixed-case objects, so I had to change them manually. Will this database/application grow to need a larger, more powerful database someday? Use uppercase and include the underscore character for better readability (CUSTOMER_DATA). Another big no-no is putting spaces in object names. bfren
www.techrepublic.com
Page 11
www.techrepublic.com
cu_surname, cu_initials, cu_address, etc. Well give the Order table the prefix or_ and name its fields or_order_id, or_cust_name_id, or_quantity, or_description, etc. So the SQL to select a trivial given row from this database looks like this:
Select * from Customer, Order Where cu_surname = "MYNAME" and cu_name_id = or_cust_name_id and or_quantity = 1;
There is a lot less typing involved in the first SQL statement, even in this trivial example. Expand this to a query with five tables and many more columns and this tips usefulness becomes more apparent. Bryce Stenberg
Page 12
www.techrepublic.com
Page 13
www.techrepublic.com
defendant code. Performance is generally bad, and these reports would run much faster if the year and type fields were separate indexed fields. rdelval
Page 14
www.techrepublic.com
When I was in college in the 1970s, I recall that the SSN was used as the student ID despite the fact that such usage was illegal. People knew that it was illegal, but they used it anyway. Decades later, as identity theft increases, the college campus I'm on now is going through the pains of removing SSN from those screens and reports that use them but don't need them. It is a major problem, mandated by the state but not funded. generalist
Page 15
www.techrepublic.com
records throughout the database without a lot of code and appending and deleting of records. This process is frequently prone to errors and should be avoided. ljboast
I do:
Select count(*) from address where and state_code = 'TN'
If you get several of these simple joins caused by the overuse of sequential keys in a table, the overhead can really mount. Stocker
Page 16
www.techrepublic.com
Page 17
www.techrepublic.com
4. Relationships
If there is a many-to-one relationship between two entities, and there is any remote possibility that it could turn into a many-to-many relationship, make it many-to-many to start with. It is harder to go from an existing many-to-one relationship to a manyto-many relationship than it is to have a many-to-many relationship to begin with. CS Data Architect
5. Use views
To provide another layer of abstraction between your database and your applications code, try building views specifically for the use of your application rather than let it access tables directly. This also provides you with a little more freedom when handling database changes. Gay Howe
Page 18
www.techrepublic.com
IF @@ERROR = 2627 -- Literal error code for Primary Key Constraint BEGIN <indicate duplication error> END
The second is a lot simpler, and in fact, utilizes the power we have given the database by all that integrity-ensuring effort. Although I personally don't like the use of the embedded literals (2627), that can be easily replaced with a bit of preprocessing. Remember, the DB is not just a repository for data; it can empower and simplify your coding. a-smith
Page 19
www.techrepublic.com
2. Use plain English (or whatever your language is) instead of codes
There are a number of good reasons why we use codes for things (e.g., 9935A might be the supply code for a box of ink pens, 4XF788-Q might be the accounting code for a business you buy things from). That's great, but users tend to think in English, not codes. The accountant who's been there for five years probably knows exactly who 4XF788-Q is, but the new accountant won't have a clue. When creating pull-down menus, lists, reports, etc., sort them by the plain-English names. If you need a code, show the user the plain-English names beside the codes. I also put a pop-up help statement telling the user that after they make their selection, only the code will appear. amasa
Page 20
www.techrepublic.com
Page 21