Return to Snippet

Revision: 72350
at July 27, 2017 04:51 by bbrumm


Initial Code
/* Primary Key */
CREATE TABLE employee (
employee_id NUMBER(10),
first_name VARCHAR2(100),
last_name VARCHAR2(100),
salary NUMBER(8),
department_id NUMBER(10),
CONSTRAINT employee_pk PRIMARY KEY (employee_id)
);



ALTER TABLE employee
ADD CONSTRAINT employee_pk PRIMARY KEY (employee_id);



ALTER TABLE employee DROP CONSTRAINT employee_pk;

ALTER TABLE employee DISABLE CONSTRAINT employee_pk;


ALTER TABLE employee ENABLE CONSTRAINT employee_pk;

/*Foreign key */

CREATE TABLE employee (
employee_id NUMBER(10),
first_name VARCHAR2(100),
last_name VARCHAR2(100),
salary NUMBER(8),
department_id NUMBER(10),
CONSTRAINT fk_emp_deptid FOREIGN KEY (department_id) REFERENCES department(department_id)
);

ALTER TABLE employee
ADD CONSTRAINT fk_emp_deptid FOREIGN KEY (department_id) REFERENCES department(department_id);


ALTER TABLE employee DROP CONSTRAINT fk_emp_deptid;

ALTER TABLE employee DISABLE CONSTRAINT fk_emp_deptid;

ALTER TABLE employee ENABLE CONSTRAINT fk_emp_deptid;

Initial URL
https://www.databasestar.com/primary-key-vs-foreign-key

Initial Description
A few examples of creating a primary key and a foreign key

Initial Title
Primary Key and Foreign Key

Initial Tags
sql, Oracle

Initial Language
SQL