Create a foreign key on the employees table that references the departments table based on the department_id field. The primary key for the employees table should be the employee number. This way, the constraint is enforced by Oracle.
#PL SQL DEVELOPER KEY CODE#
The Oracle CREATE TABLE statement for the customers table is: CREATE TABLE customersīased on the departments table below, create an Oracle table called employees that stores employee number, employee name, department, and salary information. Code language: SQL (Structured Query Language) (sql) This clause defines the groupid column in the suppliers table as a foreign key that references to the groupid column of the suppliergroups table. The Oracle CREATE TABLE statement for the suppliers table is: CREATE TABLE suppliersĬreate an Oracle table called customers that stores customer ID, name, and address information.īut this time, the customer ID should be the primary key for the table.
We could modify this CREATE TABLE statement and define the customer_id as the primary key as follows: CREATE TABLE customersĬONSTRAINT customers_pk PRIMARY KEY (customer_id)Ĭreate an Oracle table called suppliers that stores supplier ID, name, and address information. Now the only problem with this Oracle CREATE TABLE statement is that you have not defined a primary key for the table. The third column is called city which is a varchar2 datatype but can contain null values.The second column is called customer_name which is a varchar2 datatype (50 maximum characters in length) and also can not contain null values.The first column is called customer_id which is created as a number datatype (maximum 10 digits in length) and can not contain null values.This Oracle CREATE TABLE example creates a table called customers which has 3 columns.
Let's look at an Oracle CREATE TABLE example.