Create Table tablename (attribute name datatype constraint, attribute name datatype constraint, . . .)An example table is
Create Table Patron (PID NUMBER(6) Constraint pk_patron PRIMARY KEY, Name VARCHAR2(30) Constraint nn_Name NOT NULL Gender VARCHAR2(1))The above table is called patron. It contains a PID that is the key, a name attribute and a gender attribute. PID is defined to be a 6 digit integer. Name and gender are defined to be character strings with 30 and 1 char. length respectively. Note that all constraints (e.g., Primary Key) must have a constraint name (e.g., pk_patron).
In the case where a table has a composite primary key, the constraint must be formed differently. For example,
Create table Request ( CallNo VARCHAR2(10) Constraint fk_callno References Book (CallNo), PID NUMBER(6) Constraint fk_pid References Patron (PID), RDate DATE, Constraint pk_Request PRIMARY KEY (CallNo, PID))Notice that Constraints are placed after the attributes. The References constraint says that the PID in Request must match a PID in patron (i.e. Foreign Key). The data type of RDate is a special data type called DATE.
More complex table specifications can also be created.
CONSTRAINT constraintname the constraint specifications
The following are some typical constraint specifications:
ALTER TABLE tablename ADD attributename datatype constraint ADD tableconstraint MODIFY attributename datatype constraint DROP PRIMARY KEY DROP UNIQUE attributename (drops the unique constraint on an attribute) DROP CONSTRAINT constraintname ALTER TABLE Patron DROP CONSTRAINT nn_nameIt does not seem to be possible to change the name of an attribute or remove an attribute from a table.
DROP TABLE tablename
Exit to : Oracle
Hints and Tips