Application Express User's Guide > Managing Database Objects w... > Managing Tables > Creating a Table
Creating a Table |
Previous |
Next |
To create a new table:
On the Database Home Page, click the Object Browser icon.
Object Browser appears.
Click Create.
From the list of object types, select Table.
Enter a table name.
Table names must conform to Oracle naming conventions and not contain spaces or start with a number or underscore.
To have the final table name match the case entered in the Table Name field, click Preserve Case.
Enter details for each column. For each column:
Enter the column name.
Select the column type. Available types include NUMBER, VARCHAR2, DATE, TIMESTAMP, CHAR, CLOB, BLOB, NVARCHAR2, BINARY_FLOAT, and BINARY_DOUBLE
Enter the following additional information as appropriate:
Precision
Scale
To specify a column should not be NULL, select the check box in the Not Null column.
To change the order of previously entered columns, click the Up and Down arrows in the Move column. To add additional columns, click Add Column.
Click Next.
Next, define the primary key for this table (optional). A primary key is a single field or combination of fields that uniquely identifies a record.
For Primary Key, select one of the following and click Next:
No Primary Key - No primary key is created.
Populated from a new sequence - Creates a primary key and creates a trigger and a new sequence. The new sequence is used in the trigger to populated the selected primary key column. The primary key can only be a single column.
Populated from an existing sequence - Creates a primary key and creates a trigger. The selected sequence is used in the trigger to populate the selected primary key column. The primary key can only be a single column.
Not populated - Defines a primary key but does not have the value automatically populated with a sequence within a trigger. You can also select this option to define a composite primary key (that is, a primary key made up of more than one column).
Next, add foreign keys (optional). A foreign key establishes a relationship between a column (or columns) in one table and a primary or unique key in another table.
To add a foreign key:
Name - Enter a name of the foreign key constraint that you are defining.
Select Key Column(s) - Select the columns that are part of the foreign key. Once selected, click the Add icon to move them to Key Column(s).
References Table - Select the table which will be referenced by this foreign key. Then, select the columns to be referenced by this foreign key. Once selected, click the Add icon to move the selected columns to Referenced Column(s).
Select one of the following:
Disallow Delete - Blocks the delete of rows from the referenced table when there are dependent rows in this table.
Cascade Delete - Deletes the dependent rows from this table when the corresponding parent table row is deleted.
Set to Null on Delete - Sets the foreign key column values in this table to null when the corresponding parent table row is deleted.
Click Add.
Click Next.
Next, add a constraint (optional). You can create multiple constraints, but you must add each constraint separately.
To add a constraint:
Specify the type of constraint (Check or Unique).
A check constraint is a validation check on one or more columns within the table. No records can be inserted or updated in a table which violates an enabled check constraint. A unique constraint designates a column or a combination of columns as a unique key. To satisfy a unique constraint, no two rows in the table can have the same values for the specified columns.
Enter the constraint in the field provided. For unique constraints, select the column(s) that are to be unique. For check constraints, enter the expression that should be checked such as, flag in ('Y','N')
.
Click Add.
Click Finish.
A confirmation page appears. To view the SQL used to create the table, click SQL Syntax.
Click Create.
Note that you do not need to follow the steps for creating a table in the order described in the previous procedure. Instead of navigating through the wizard by clicking the Next and Previous button, you can also access a specific step by selecting it in the progress indicator on the left side of the page.