


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



































1
CREATE TABLE Customer (SSN CHAR(11), age INTEGER, income REAL, PRIMARY KEY (SSN), CONSTRAINT CustAge CHECK (age > 18), CONSTRAINT notEmp CHECK (SSN NOT IN (SELECT empSSN FROM Employee))); However, nested subquery not allowed for check constraint in Oracle (or most DBMSs). Alternative: Trigger (later) You can give the constraint a name
16 CREATE OR REPLACE TYPE full_address_type AS OBJECT ( Street VARCHAR2(80), City VARCHAR2(80), State CHAR(2), Zip VARCHAR2(10) ); )
17 CREATE OR REPLACE TYPE full_address_type AS OBJECT ( Street VARCHAR2(80), City VARCHAR2(80), State CHAR(2), Zip VARCHAR2(10) ); ); CREATE TABLE Customer ( full_name full_name_type, full_address full_address_type ); INSERT INTO Customer VALUES ( full_name(‘John’, ‘Smith’), full_address(‘4400 University Dr’, ‘Fairfax’, ‘VA’, ‘22030’) );
19 CREATE TABLE chicken(cID INT PRIMARY KEY," eID INT);" CREATE TABLE egg(eID INT PRIMARY KEY," cID INT);" " ALTER TABLE chicken ADD CONSTRAINT chickenREFegg" FOREIGN KEY (eID) REFERENCES egg(eID)" INITIALLY DEFERRED DEFERRABLE;" " ALTER TABLE egg ADD CONSTRAINT eggREFchicken" FOREIGN KEY (cID) REFERENCES chicken(cID)" INITIALLY DEFERRED DEFERRABLE;"
Deferring Constraint Checking, Cont’d 20 CREATE TABLE chicken(cID INT PRIMARY KEY," eID INT);" CREATE TABLE egg(eID INT PRIMARY KEY," cID INT);" " ALTER TABLE chicken ADD CONSTRAINT chickenREFegg" FOREIGN KEY (eID) REFERENCES egg(eID)" INITIALLY DEFERRED DEFERRABLE;" " ALTER TABLE egg ADD CONSTRAINT eggREFchicken" FOREIGN KEY (cID) REFERENCES chicken(cID)" INITIALLY DEFERRED DEFERRABLE;" Tells Oracle to do deferred constraint checking until the COMMIT point To insert: INSERT INTO chicken VALUES(1, 2);" INSERT INTO egg VALUES(2, 1);" COMMIT;"