Web site counters - Chapter 4 Exercise 1 solution Five CREATE TABLE
Chapter 4 Exercise 1 solution Five CREATE TABLE commands are shown here. Note that the order in which tables are created is important, as assignment of foreign key columns requires that primary keys in parent tables already exist: CREATE TABLE Customer ( customer_name VARCHAR(32) PRIMARY KEY, customer_address VARCHAR(256), customer_phone VARCHAR(32) ); CREATE TABLE Stock_Source_Department ( stock_source_department VARCHAR(32) PRIMARY KEY, stock_source_city VARCHAR(32) NOT NULL ); CREATE TABLE Stock_Item ( stock# INTEGER PRIMARY KEY, stock_source_department VARCHAR(32) NOT NULL REFERENCES Stock_Source_Department, stock_description VARCHAR(256), stock_unit_price FLOAT ); CREATE TABLE Sale_Order ( order# INTEGER PRIMARY KEY, customer_name VARCHAR(32) REFERENCES Customer, dte DATE, sales_tax_percentage FLOAT ); CREATE TABLE Sale_Order_Item ( order# INTEGER PRIMARY KEY, stock# INTEGER NOT NULL REFERENCES Sale_Order, stock_quantity INTEGER ); Note how the PRIMARY KEY and FOREIGN KEY specifications are included within the specification of the column. These are called in line constraint definitions. This is a different method of definition from that of exercises in Chapter 3. Chapter 3 uses what are called out of line constraint definitions. Inline constraint definitions can only be used for constraints on single columns. For example, a multiple column primary key would have to be defined as an out of line constraint. It is also possible to define primary and foreign key constraints using an ALTER TABLE command to change a table specification, after the table has already been created. 422 Appendix A
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.