Java Reference
In-Depth Information
3. Enter lines 48 through 67 as shown in Figure 11-17 on page 710.
The Users and Stocks tables are dropped, and their respective indexes are
dropped implicitly (Figure 11-23). Because the UserStocks table was dropped
first, there are no foreign keys referencing fields in either of these two tables.
tables
dropped
tables
dropped
FIGURE 11-23
Once it is certain that the tables and indexes are dropped, it is safe to create
them. You cannot create a table or an index that already exists, which is why they
had to be dropped first.
Creating Tables, Indexes, and Keys
When creating tables, the order can be important; the relationships between
the tables must be considered. Because the UserStocks table is comprised of
fields that are foreign keys to the Users and Stocks tables, these two tables must
be created before the UserStocks table.
CREATE TABLE is the SQL statement to create a new table. The table name is
defined and then the fields in the table are listed along with their data types,
lengths, if appropriate, and any constraints. A constraint is a rule that restricts
the data value entered in a column. Constraints can be of two types, integrity or
value. An integrity constraint is used to identify a primary or a foreign key. A
value constraint is used to specify the allowable value of data in a column, such
as a data range, a specific data value, or whether the data value must be unique
or not null. If a field is marked as NOT NULL, then a value is required; specifi-
cally, it must contain some data. Constraints can be applied at one of two levels.
A table constraint restricts the field value with respect to all other values in the
table. For example, a primary key must have a unique value for each record, and
a primary key constraint is a table constraint. A column constraint (also known
as a field-level constraint) limits the value placed in a specific column,
regardless of values in other records. A constraint can be named by using the
CONSTRAINT keyword, and the given name must be unique within the entire
database, not just the table. Typically, primary and foreign key constraints are
 
Search WWH ::




Custom Search