March 25th, 2009

Converting Data into Tables (Part 1 of 2)

Posted by admin in O. Database Objects

A database table is a two-dimensional array of columns and rows. Tables normally describe places (such as stores), people (such as customers), objects (such as inventory), or relationships (such as sales transactions).

Let’s say that you wish to create a customer table. You might consider the following attributes:

                    Customer ID
                    Customer First Name
                    Customer Last Name
                    Customer Street Address
                    Customer City
                    Customer State
                    Customer Zip Code
                    Customer Phone Number
                    Customer Credit Limit

You can build an SQL command to create this table. For each column, you specify its name, its data type, and possibly one or more constraints as follows:

          CREATE TABLE CUSTOMER_TABLE (
                        CUST_ID                INTEGER        NOT NULL,
                        FIRST_NAME         CHAR(20),
                        LAST_NAME           CHAR(30)      NOT NULL,
                        STREET_ADDRESS CHAR(30),
                        CITY                       CHAR(20),
                        STATE                    CHAR(2),
                        ZIP_CODE              INTEGER,
                        PHONE_NUMBER    CHAR(14),
                        CREDIT_LIMIT        DECIMAL(11,2)
                        );

Now let’s consider creating a sales transaction table. If you have questions about the sale, you would like to have a phone number. If you put the phone number on the sales transaction, you will be repeating the same phone number on each sales ticket for each item processed, but the customer is buying your product and the phone number would occur only once if it is in the customer table. If you wish to change the phone number, you have only one place to change it if it is in the customer table. Look for the most logical association for locations of data.

Comments are closed.

Sorry, the comment form is closed at this time.