Professional Documents
Culture Documents
(NOT: Ufak farklar izimlerde, total participation gibi. Snavlarda kitaptaki izim kurallar geerlidir, aradaki farklar kendiniz giderin.)
1. Entity and Attributes: Entity: Employee Entity Set: Employees Attributes: ssn name lot Primary Key: ssn
name snn lot
Employees
Schema: Employees(ssn,name,lot) SQL: CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER, PRIMARY KEY (ssn))
Employees
Works_In
Departments
Schema: Works_In(ssn,did,since) SQL: CREATE TABLE Works_In( ssn CHAR(1), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) 3. Key Constraints Each department has at most one manager (one-to-many relationship: a manager employee can manage one or more departments).
since name ssn lot did dname budget
Employees
Manages
Departments
Translation into relational data model in two ways: I. A separate table for relationship set Schema: Manages(ssn,did,since) SQL: CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) Combine relationship with the entity set that contributes its key to the relationship (due to one-to-many relationship, at most one manager for each department) Schema: Dept_Mgr(did,dname,budget,ssn,since) SQL: CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees)
II.
4. Participation Constraints Two types of participation of an entity set in a relationship set: Total: Represented with a tick line. Example: Every department has a manager. Partial: Represented with a regular line. Example: Some employees are managers.
Employees
Manages
Departments
Works_In
since
Schema: Dept_Mgr(did,dname,budget,ssn,since) SQL: CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees ON DELETE NO ACTION) 5. Weak Entities Entities that cannot be identified uniquely by given attributes (no key attributes) but by considering the primary key of another entity (owner). Represented with tick-line boxes.
name ssn lot cost pname age
Employees
Policy
Dependents
Schema: Dep_Policy(pname,ssn,age,cost) SQL: CREATE TABLE Dep_Policy ( Weak entity set Must have total pname CHAR(20), participation age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (pname, ssn), FOREIGN KEY (ssn) REFERENCES Employees ON DELETE CASCADE)
6. 'ISA' hierarchies Used to represent entity subsets. Used in the case subsets have distinct attributes, and/or have special association with other entities (relationships). Example: Employees are hourly and/or contract employees.
ssn
name lot
Employees
hourly_wages
Hourly_Emps
Contract_Emps
7. Aggregation Used when we have to model a relationship involving (entitity sets and) a relationship set. Example: Monitoring relationship between Employees entity set and Sponsors relationship set.
name ssn Employees lo
Monitors
until
SQL CREATE TABLE Employees ( Ssn CHAR(11), Name CHAR(25), Lot CHAR(2) PRIMARY KEY (ssn)) CREATE TABLE Projects ( pid CHAR(10), started_on DATE, pbudget REAL, PRIMARY KEY (pid) NOT NULL) CREATE TABLE Sponsors ( pid CHAR(10), did CHAR(10), PRIMARY KEY (pid,did), FOREIGN KEY (pid) REFERENCES Projects, FOREIGN KEY (did) REFERENCES Departments) CREATE TABLE Departments ( did CHAR(10), dname CHAR(25), budget REAL, PRIMARY KEY (did) NOT NULL) CREATE TABLE Monitors ( ssn CHAR(11), pid CHAR(10), did CHAR(10), PRIMARY KEY (ssn,pid,did), FOREIGN KEY (pid) REFERENCES Projects, FOREIGN KEY (did) REFERENCES Departments FOREIGN KEY (ssn) REFERENCES Employees)