Information About

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 28 November 2006

On DB2 Naming Conventions

Posted on 08:52 by Unknown
What's in a name? The establishment and enforcing of naming conventions is often one of the first duties to be tackled when implementing new software. Adequate thought and preparation is required in order for such a task to be successful. What amount of effort should be extended in the creation of appropriate database naming standards? Are current industry standards acceptable?

Shakespeare, many, many years ago, may have said it best when he wrote: "What's in a name? That which we call a rose by any other name would smell as sweet." But, if that is true, then why do those of us in IT spend so much time and effort developing and enforcing naming standards? Maybe what something is called is not quite so trivial a matter after all!

Well, we know what Shakespeare was trying to convey: the name by which we call something has no effect upon the actual object. Calling a desk a lamp will not turn it into a lamp: it is still a desk. Let's not forget this.

In today's blog, though, I want to offer a basic approach to database naming standards, and DB2 for z/OS naming standards, in particular.

Tables and Their Cousins

In an today's SQL DBMSes the primary access point for data is the "table." A table consists of multiple rows, each with a fixed and unchanging number of defined columns. But there are several table alternatives that behave just like tables. For example, DB2 allows the following:

  • ALIAS - an alternative name that can be used in SQL statements to refer to a table or a view in the same or a remoteDB2 subsystem.
  • SYNONYM - an alternative name that can be used in SQL statements to refer to a table or a view in the same DB2 subsystem. Synonyms are accessible only by the synonym owner.
  • VIEW - an alternative representation of data from one ormore tables or views.
These three alternative means of access are similar in one way: they all present data by means of values in rows and columns. An end user need not know whether he or she is querying a table, an alias, a synonym, or a view -- the results are the same, namely data represented by values in rows and columns.

So why do some shops impose different naming standards on views than they do on tables? It makes sense to use the exact same naming convention for tables, views, aliases, and synonyms. These four database objects all logically refer to the same thing - a representation of data in terms of columns and rows.

Why would you want to implement different naming conventions for each of these objects? Let's examine the pros and cons. Consider your current table naming conventions. If your shop is typical, you will find a convention that is similar to this:

Format: aaa_dddddddddddddd

Example: ORD_ITEM

Here aaa is a three character application identifier and the remainder is a free-form alphanumeric description of the table. In the example we have the three character ORD (representing perhaps "order entry" followed by an underscore and ITEM. So this is the "item" table in the order entry system.

If your standards are significantly different, pause for a moment to ask yourself why. The format shown is almost an industry standard for table naming. You most surely do not want to force every DB2 table to begin with a T (or have a strategically embedded T within the table name). The name of a DB2 table should accurately and succinctly convey the contents of the data it contains. The naming convention displayed in Figure 1 accomplishes this.


So this brings us to our second naming convention recommendation: avoid embedding a 'T', or any other character, into table names to indicate that the object is a table. Likewise, indicator characters should be avoided for any other table-like object (i.e. aliases, synonyms, and views). Although most shops avoid embedding a 'T' in the table name, many of these same shops do embed a character into alias, synonym, and especially view names. The primary reason given is that the character makes it easy to determine what type of object is being accessed just by looking at the name.

There are two reasons why this is a bad idea. The first is a semantic reason, the second a flexibility issue. In semantic terms, an object's name need only identify the object, not the object's type. Consider the following arguments: How are people named? Usually one can ascertain the gender of someone simply by knowing their name but would you banish all males named Chris, Pat, or Terry? Or maybe all females named Chris, Pat, and Terry? After all, men and women are different. Shouldn't we make sure that all men's names are differentiated from women's names? Maybe we should start all men's names with an 'M' and all women's names with a W? If we did, we'd sure have a lot of Marks and Wendys, wouldn't we? The point here is that context enables us to differentiate men from women, when it is necessary. The same can be said of database objects.

How about another example: how are COBOL program variables named? Do you name your 01, 05, and 77 level variable names differently in your COBOL programs? For example, do all 01 levels start with 'O' (for one), all 05 levels start with 'F', and all 77 levels start with 'S'? No? Why not? Isn't this the same as forcing views to start with V (or having a strategically embedded V within the name)?

What about the naming of pets? Say I have a dog, a cat, and a bird. Now, I wouldn't want to get them confused, so I'll make sure that I start all of my dog names with a D, cat names with a C, and bird names with a B. So, I'll feed C_FELIX in the morning, take D_ROVER for a walk after work, and make sure I cover B_TWEETY's cage before I go to bed. Sounds ridiculous, doesn't it?

The whole point of this tirade is that if we don't manufacture hokey names in the real world, why would we want to do it with our DB2 objects? There is really no reason to embed special characters into DB2 objects names to differentiate them from one another. It is very practical and desirable to name DB2 objects in a consistent manner, but that consistent manner should be well-thought-out and should utilize the system to its fullest capacity wherever possible.

The second reason for this rule is to increase flexibility. Say, for example, that we have a table that for some reason is significantly altered, dropped, or renamed. If views are not constrained by rigid naming conventions requiring an embedded 'V' in the name, then a view can be constructed that resembles the way the table used to look. Furthermore, this view can be given the same name as the old table. This increases system flexibility. Most users don't care whether they are using a table, view, synonym, or alias. They simply want the data. And, in a relational database, tables, views, synonyms, and aliases all logically appear to be identical to the end user: as rows and columns.

Although it is true that there are certain operations that cannot be performed on certain types of views, the users who need to know this will generally be sophisticated users. For example, very few shops allow end users to update any table they want using QMF, SPUFI, or some other tool. Updates, deletions, and insertions (the operations which are not available to some views) are generally coded into application programs and scheduled in batch or executed on-line in transactions. The end user does need to query tables dynamically. Now you tell me, which name will your typical end user remember more readily when he needs to access his marketing contacts: MKT_CONTACT or VMKTCT01?

Further Arguments For Indicators

Some folks believe they have very valid reasons for embedding an object type indicator character into database objects - view names, in particular. Let's examine these arguments.

Point Embedding a V into our view names enables our DBAs to quickly determine which objects are views and which are tables.

Counterpoint Many of these shops do not embed a T into the table name, but feel that a V in the view name is necessary. It is believed that the DBA will be able to more easily discern views from tables. But, rarely do these shops force an S into synonym names or an A into alias names. Even if they do, it is usually overkill. Any good DBA already knows which objects are tables and which are views, and if he or she doesn't, a simple query against the system catalog will clarify the matter. For example, in DB2, this query will list all table-like objects:

SELECT NAME, CREATOR, "TABLE"
FROM SYSIBM.SYSTABLES
WHERE TYPE = "T"
UNION ALL
SELECT NAME, CREATOR, "ALIAS"
FROM SYSIBM.SYSTABLES
WHERE TYPE = "A"
UNION ALL
SELECT NAME, CREATOR, "SYNONYM"
FROM SYSIBM.SYSSYNONYMS
UNION ALL
SELECT NAME, CREATOR, "VIEW"
FROM SYSIBM.SYSVTREE
ORDER BY 3, 1;

Point It is necessary to code view names differently so that users understand that they are working with a view and not all operations can be performed on the view.

Counterpoint All operations can be performed on some views but not all operations can be performed on all tables! What if the user does not have the security to perform the operation? For example, what is the difference, from the user's perspective, between accessing a non-updateable view and accessing a table where only the SELECT privilege has been granted?

Use It or Lose It

Another common problem with database naming conventions is unnecessary size restrictions. Using DB2 as an example, most objects can have a name up to 18 characters long (even more after moving to DB2 V8). But, in many instances, shops establish naming standards that do not utilize all of the characters available. This is usually unwise, which brings us to our third recommendation: Unless a compelling reason exists, ensure that your standards allow for the length of database object names to utilize every character available.

Here is a list of maximum and recommended lengths for names of each DB2 object:


----------------------------------------------------------
Recommended
DB2 Object Max Length (V7) Max Length(V8) Length
---------- --------------- -------------- -----------
STOGROUP 8 128 128
Database 8 8 8
Tablespace 8 8 8
Table 18 128 128
View 18 128 128
Alias 18 128 128
Synonym 18 128 128
Column 18 128 128
Check Constraint 18 128 128
Ref. Constraint 8 128 128
Index 18 128 8
----------------------------------------------------------




Notice that, except for indexes, the recommended length is equal to the maximum length for each object. Why are indexes singled out in DB2? This is an example of a compelling reason to bypass the general recommendation. Developers can explicitly name DB2 indexes, but they cannot explicitly name DB2 index spaces. Yet, every DB2 index requires an index space - and an index space name. The index space name will be implicitly generated by DB2 from the index name. If the index name is 8 characters or less in length, then the index space name will be the same as the index name. However, if the index name is longer than 8 characters, DB2 will use an internal, proprietary algorithm to generate a unique, 8-byte index space name. As this name cannot be determined prior to index creation, it is wise to limit the length of index names to 8 characters. Also, since the only folks who will be interested in the index space name are DBAs, there is no reason to make the names more descriptive for general end users... and DBAs are used to dealing with cryptic names (some of them even like it).

This is a good example of the maxim that there are exceptions to every rule.

Another exception may be that users of DB2 V8 may want to impose V7 length restrictions on their objects. You might want to do this to discourage verbose names (128 is a BIG extension over 18 bytes). Maybe you have applications that cannot easily use or display such wordy object or column names.

Embedded Meaning

One final troublesome naming convention used by some shops is embedding specialized meaning into database object names. The name of an object should reflect what that object is or represents. However, it should not attempt to define the object and describe all of its metadata.

With this in mind, it is time for another recommendation: Do not embed specialized meaning into database object names.

Let's examine this in more detail by means of an example. Some shops enforce DB2 index naming conventions where the type of index is embedded in the index name. Consider the following example:

Format: Xaaaaayz

Example: XORDITCU

Here X is a constant, aaaaa is unique five character description (perhaps derived from the table name), y is an indicator for clustering (either C for clustered or N for nonclustered), and z is an indicator for index type (P for primary key, F for foreign key, U for unique, and N for non-unique).

So, the example is a unique, clustering index on the ORD_ITEM table. Note two potential problem areas with this standard:

  • An embedded X identifies this object as an index.

  • Embedded meaning in the form of indicators detailing the type of index.

The embedded indicator character 'X', although unnecessary, is not as evil as indicator characters embedded in table-like objects. Indexes are not explicitly accessed by users. Therefore, obscure or difficult-to-remember naming conventions are not as big of a problem. The same arguments hold true for tablespace names. In fact, indicator characters may actually be helpful to ensure that tablespaces and indexes are never named the same. Within the same database, DB2 does not permit a tablespace to have the same name as any index, and vice versa. DB2 uses a name generation algorithm to enforce uniqueness if it is attempted. So, if you must use indicator characters in database names, use them only in objects which are never explicitly accessed by end users.

The second potential problem area poses quite a bit of trouble. Consider the following cases which would cause the embedded meaning in the index name to be incorrect:

  • The primary key is dropped.

  • A foreign key is dropped.

  • The index is altered from non-unique to unique (or vice versa) using a database alteration tool.

In each of these cases we would have to re-name the index or we would have indexes with embedded characters that did not accurately depict the metadata for the index. Both are undesireable.

And there are additional problems to consider with this naming convention, as well. What if an index is defined for a foreign key, but is also unique? Should we use an 'F' or a 'U'? Or do we need another character?

The naming convention also crams in whether the index is clustering ('C') or not ('N'). This is not a good idea either. Misconceptions can occur. For example, in DB2, if no clustering index is explicitly defined, DB2 will use the first index created as a clustering index. Should this index be named with an embedded 'C' or not? And again, what happens if we switch clustering indexes - we would have to re-name indexes.

Let's look at one final example from the real world to better illustrate why it is a bad idea to embed specialized meaning into database object names. Consider what would happen if we named corporations based upon what they produce. When IBM began, they produced typewriters. If we named corporations like some of us name database objects, the company could have been named based upon the fact that they manufactured typewriters way back when. So IBM might be called TIBM (the T is for typewriters).

Now guess what, TIBM doesn't make typewriters any longer. What should we do? Rename the company or live with a name that is no longer relevant? Similar problems ensure with database object names over time.

Synopsis

Naming conventions evoke a lot of heated discussion. Everybody has their opinion as to what is the best method for naming database objects. Remember, though, that it is best to keep an open mind.

It is just like that old country novelty hit "A Boy Named Sue." Johnny Cash may have been upset that his father gave him a girl's name, but that was before he knew why. In a similar manner, I hope that this blog topic caused you to think about naming conventions from a different perspective. If so, I will consider it a success.

Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • DB2 Locking, Part 8: LOBs and Locking
    When a row is read or modified in a table containing LOB columns, the application will obtain a normal transaction lock on the base table. T...
  • DB2 for z/OS Version 9 Beta Announcement
    On May 2, 2006 IBM announced the beta for the next version of mainframe DB2: namely, DB2 V9.1 for z/OS. You can view the announcement here ....
  • Index on Expressions [DB2 9 for z/OS]
    DB2 9 for z/OS offers, for the first time, the ability to create an index on data that is not technically in the table. At this point, you m...
  • When Not to Index
    Answering a question I got via e-mail on indexing... Every now and then I take the opportunity to blog about a question I get through e-...
  • CLONE Tables [DB2 9 for z/OS]
    This new feature in DB2 V9 might sound like an old monster movie ( Invasion of the Clone Tables!!! ), but it is actually a nifty new capabil...
  • DB2 Locking, Part 2: Table Space and Table Locks
    Today's post is the second in our DB2 locking series and it covers the topic of table space and table locks. Table Space Locks A table s...
  • IBM Manages the Data Lifecycle
    Data lifecycle is a somewhat new-ish term, at least in terms of what I plan to talk about in this blog posting. The data lifecycle – and dat...
  • IBM Announces DB2 10 for z/OS Beta Program
    IBM announced the beta program for the next version of DB2 today, now "officially" known as DB2 10 (no more DB2 X). It is a closed...
  • DB2 Locking, Part 5: Lock Suspensions, Timeouts, and Deadlocks
    The longer a lock is held, the greater the potential impact to other applications. When an application requests a lock that is already held ...
  • DB2 Locking, Part 15: Tackling Timeout Troubles
    Many shops battle with locking issues and frequently, the cause of performance issues can be traced back to locking issues, more specificall...

Categories

  • .NET
  • ACID
  • ALTER
  • analytics
  • articles
  • automation
  • award
  • backup
  • best practices
  • BETWEEN
  • BI
  • Big Data
  • BIND
  • blogging
  • book review
  • bufferpool
  • buffers
  • CASE
  • change management
  • claim
  • Cognos
  • COMMIT
  • compliance
  • compression
  • conference
  • constraints
  • COPY
  • data
  • data breaches
  • data quality
  • data security
  • Data Sharing
  • data types
  • data warehouse
  • database archiving
  • database auditing
  • database design
  • date
  • DB2
  • DB2 10
  • DB2 11
  • DB2 9
  • DB2 Analystics Accelerator
  • DB2 Catalog
  • DB2 conversion
  • DB2 Developer's Guide
  • DB2 X
  • DB2-L
  • DBA
  • DDL
  • developerWorks
  • dirty read
  • DISPLAY
  • DL/1
  • drain
  • DSNZPARM
  • Dynamic SQL
  • eBook
  • education
  • enclave SRB
  • encryption
  • ERP
  • FETCH FIRST
  • Freakonomics
  • functions
  • generosity factor
  • Happy Holidays
  • Happy New Year
  • Hibernate
  • HIPAA
  • history
  • IBM
  • ICF
  • IDUG
  • IFL
  • IMS
  • index
  • Information Agenda
  • Informix
  • InfoSphere
  • infrastructure
  • integrity
  • IOD
  • IOD11
  • IOD2009
  • IOD2011
  • IODGC
  • IRLM
  • ISOLATION
  • Java
  • JDBC
  • load balancing
  • LOBs
  • locking
  • LUW
  • mainframe
  • Malcolm Gladwell
  • manuals
  • memory
  • middleware
  • migration
  • misc
  • monitoring
  • natural key
  • Netezza
  • new blog location
  • NoSQL
  • nulls
  • OLAP
  • optimization
  • Oracle versus DB2
  • packages
  • PCI-DSS
  • performance
  • PIECESIZE
  • poll
  • primary key
  • production data
  • programming
  • Q+A
  • QMF
  • REBIND
  • recovery
  • RedBook
  • regulatory compliance
  • reliability
  • REORG
  • research
  • RI
  • RTO
  • salaries
  • SAP
  • scalability
  • security
  • smarter planet
  • SoftwareOnZ
  • sort
  • SOX
  • specialty processors
  • SPUFI
  • SQL
  • Stage 1
  • Stage 2
  • standards
  • Steelers
  • storage
  • stored procedures
  • stream computing
  • surrogate key
  • SYSADM
  • Sysadmin
  • table expressions
  • table space
  • TechDoc
  • tips and tricks
  • Top Ten
  • trace
  • training
  • triggers
  • Twitter
  • UDFs
  • UNION
  • unstructured data
  • user groups
  • utilities
  • V1
  • V10
  • V2
  • V3
  • V4
  • V5
  • V6
  • V7
  • V8
  • V9
  • variables
  • views
  • VOLATILE
  • Web 2.0
  • webinar
  • Wordle
  • XML
  • z/OS
  • zAAP
  • zIIP

Blog Archive

  • ►  2014 (2)
    • ►  January (2)
  • ►  2013 (50)
    • ►  December (6)
    • ►  November (6)
    • ►  October (5)
    • ►  September (5)
    • ►  August (3)
    • ►  July (7)
    • ►  June (4)
    • ►  May (4)
    • ►  April (5)
    • ►  March (1)
    • ►  February (2)
    • ►  January (2)
  • ►  2012 (17)
    • ►  December (1)
    • ►  November (2)
    • ►  October (3)
    • ►  August (2)
    • ►  July (1)
    • ►  May (1)
    • ►  April (1)
    • ►  March (2)
    • ►  February (2)
    • ►  January (2)
  • ►  2011 (27)
    • ►  December (1)
    • ►  November (1)
    • ►  October (6)
    • ►  September (2)
    • ►  August (3)
    • ►  July (2)
    • ►  June (3)
    • ►  May (2)
    • ►  April (3)
    • ►  March (1)
    • ►  February (3)
  • ►  2010 (29)
    • ►  December (1)
    • ►  October (6)
    • ►  September (1)
    • ►  August (2)
    • ►  July (2)
    • ►  June (1)
    • ►  May (3)
    • ►  April (3)
    • ►  March (3)
    • ►  February (4)
    • ►  January (3)
  • ►  2009 (43)
    • ►  December (5)
    • ►  November (4)
    • ►  October (6)
    • ►  September (2)
    • ►  August (1)
    • ►  July (3)
    • ►  June (2)
    • ►  May (3)
    • ►  April (2)
    • ►  March (4)
    • ►  February (5)
    • ►  January (6)
  • ►  2008 (44)
    • ►  December (1)
    • ►  November (4)
    • ►  October (4)
    • ►  September (6)
    • ►  August (1)
    • ►  July (4)
    • ►  June (3)
    • ►  May (5)
    • ►  April (4)
    • ►  March (4)
    • ►  February (2)
    • ►  January (6)
  • ►  2007 (51)
    • ►  December (2)
    • ►  November (3)
    • ►  October (5)
    • ►  September (3)
    • ►  August (6)
    • ►  July (4)
    • ►  June (4)
    • ►  May (5)
    • ►  April (8)
    • ►  March (5)
    • ►  February (4)
    • ►  January (2)
  • ▼  2006 (60)
    • ▼  November (4)
      • On DB2 Naming Conventions
      • Character Versus Numeric Data Types
      • DB2 Access Paths and Change Management Procedures
      • Try Out the XML Capability of DB2 9 for Free
    • ►  October (8)
    • ►  September (4)
    • ►  August (11)
    • ►  July (7)
    • ►  June (2)
    • ►  May (7)
    • ►  April (3)
    • ►  March (6)
    • ►  February (4)
    • ►  January (4)
  • ►  2005 (11)
    • ►  December (3)
    • ►  November (6)
    • ►  October (2)
Powered by Blogger.

About Me

Unknown
View my complete profile