CREATING AND MODIFYING TABLES
Creating tables with CREATE TABLE
• A database table looks a lot like a spreadsheet table: a two-dimensional array made up of rows and columns. You can create a table by using the SQL CREATE TABLE command. Within the command, you specify the name and data type of each column.
• After you create a table, you can start loading it with data. If requirements change, you can change a table’s structure by using the ALTER TABLE command. If a table outlives its usefulness or becomes obsolete, you can eliminate it with the DROP command. The various forms of the CREATE and ALTER commands, together with the DROP command, make up SQL’s DDL.
• Normalization, an extensive field of study in its own right, is a way of structuring database tables so that updates don’t introduce anomalies. Each table you create contains columns that correspond to attributes that are tightly linked to each other.
• You may, for example, create a CUSTOMER table with the attributes CUSTOMER. CustomerID, CUSTOMER.FirstName, CUSTOMER.LastName, CUSTOMER.Street, CUSTOMER.City, CUSTOMER.State, CUSTOMER.Zipcode,
and CUSTOMER.Phone. All these attributes are more closely related to the customer entity than to any other entity in a database that may contain many tables. These attributes contain all the relatively permanent customer information that your organization keeps on file.
EXAMPLE:
CREATE TABLE CUSTOMER (
Customer ID INTEGER NOT NULL
FirstName CHAR(15),
LastName CHAR(20) NOT NULL,
Street CHAR(25),
City CHAR(20),
State CHAR(2),
Zipcode CHAR(10),
Phone CHAR(13),
For each column, you specify its name (for example, CustomerID), its data type (for example, INTEGER), and possibly one or more constraints (for example, NOT NULL)