Database Reference
In-Depth Information
Remember that these are guidelines. You can implement however you
want, but in the long run, having everything in lowercase will cause you
fewer headaches.
Naming Tables
When we name our tables, we use a convention of prefacing the table with
“tbl_” followed by a meaningful name. We do this so that you can quickly
identify a table when looking at objects or queries. Some people would
argue that it is obvious which objects are tables, because they are listed as
tables in the SQL Server tools and they are always referenced in the same
places in T-SQL statements. We agree with the first argument, but as for
the second, it forgets about views. Views and tables are referenced in the
same way, and it is often helpful to be able to quickly identify whether a
view or table is being used when you're looking at a T-SQL statement.
Additionally, you might need to look at documentation, such as a data dic-
tionary, offline. It is again helpful to be able to quickly identify your tables.
As for the actual name, we make sure it's meaningful and we separate
words with underscore characters. One other important note: We never
pluralize the names of our tables. The table is named for the data it holds,
as in tbl_customer; even though it holds multiple customers, we do not
name the table tbl_customers. Here are some of the tables you will see in
the Mountain View Music database:
tbl_order
tbl_customer
tbl_product
tbl_employee
That convention handles 80 percent of the tables we will encounter in
our database, but there is always the other 20 percent to deal with. Some
tables serve a special purpose, such as join tables in many-to-many rela-
tionships. You may decide that you need to set up a M:M relationship be-
tween a customer table and an address table. If you think about it, this
makes sense; a customer can have many addresses, and more than one cus-
tomer can share an address. As we discussed in Chapter 3, you need to cre-
ate a third join table to set up this M:M relationship. In this case, we start
the table name with “tbl_” and then we use both of the other table names
in this new name. In the example of customers and addresses, we would
call the join table tbl_customer_address.
Search WWH ::




Custom Search