



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Example (CASCADE). CREATE TABLE dependent ( … FOREIGN KEY (essn) REFERENCES employee. ON DELETE CASCADE, …) Example (SET NULL). CREATE TABLE employee (.
Typology: Schemes and Mind Maps
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Creating (CREATE), Modifying (ALTER), and Removing (DROP) Catalogs Schemas Relations (Tables) Constraints Domains
CREATE TABLE department ( dname Text UNIQUE NOT NULL, dnumber Integer PRIMARY KEY, mgrssn Integer REFERENCES employee, mgrstartdate Date );
CREATE TABLE dependent ( essn Integer, dependent_name Text, sex Text, bdate Date, relationship Text, CONSTRAINT deppk PRIMARY KEY (essn,dependent_name), CONSTRAINT empfk FOREIGN KEY (essn) references employee );
Numeric: integer(n) (SQLServer: int) decimal(p,s) (or number(p,s)) Character: char(n) varchar(n) Other: date time (SQLServer: datetime) p: precision (total #digits) s: scale (#digits after .)
Numeric: number, integer Character: text (only up to 255 characters) Other: Yes/No Date/Time Currency (15 + 4) Memo (64K text) Hyperlink OLE Object Autonumber
Find further examples for ON UPDATE CASCADE ON DELETE CASCADE ON DELETE SET NULL ON DELETE SET DEFAULT Find strategies for foreign keys in company database
Drop behaviors: cascade and restrict DROP TABLE Dependent CASCADE; DROP TABLE Dependent RESTRICT; only drops if no element of table is referenced
ALTER TABLE table_name ADD attribute; ADD constraint; DROP attribute [CASCADE|RESTRICT] DROP constraint_name [CASCADE|RESTRICT] ALTER attribute [DROP DEFAULT| SET DEFAULT value]
ALTER TABLE employees ADD Age Number; ALTER TABLE employees ADD FOREIGN KEY dno REFERENCES Department(dnumber); ALTER TABLE employees DROP empsuperfk;
Some systems do not allow references to tables that do not exist yet. Two solutions: if no cyclical dependencies: create tables in right order in case of cyclical dependencies: create tables without f.k. constraints, and use ALTER TABLE to add these later (Example: companyaccess.sql)
A view is a virtual table based on one or more defining tables ; in SQL it is created as the result of a select query. CREATE VIEW view_name AS SELECT … ; Or (to name columns) CREATE VIEW view_name(column names) AS SELECT …;
Updating views can be problematic: