Академический Документы
Профессиональный Документы
Культура Документы
Topics
RDBMS Terminology Primary Key Foreign Key Candidate Key Integrity Constraints Transforming ER Models into Relations
SDLC revisited
Project Identification and Selection Project Initiation and Planning Analysis
Implementation Maintenance
Tuples Relation
C a r d i n a li t y
Instance Degree
Copyright 2012 Pratian Technologies www.pratian.com
RDBMS Terminology
Formal Relational Term Relation Tuple Cardinality Attribute Degree Primary Key Domain Informal Equivalents Table Row, Record Number of Rows Column, Field Number of Columns Unique Identifier Set of legal values
Definitions
Primary Key
An attribute ( or combination of attributes ) that uniquely identifies each row in a relation
Composite key
A primary key that consists of more than one attribute
Foreign Key
Attribute or attribute combination of one table whose values are required to match those of the primary key of some other table Each Foreign key represents a relationship between two entity types.
Foreign Key
AUTHORS TABLE AUTHORID A1 NAME SHOBHA DE CITY MUMBAI COUNTRY INDIA
PUBLISHER TABLE PUB_ID P1 NAME MCGRAW HILL CITY NEW YORK WORK TABLE AUTHORID A1 PUB_ID P1 TITLE SISTERS COUNTRY U.S.A
Integrity Constraints
Domain Constraints
All the values that appear in a column must be taken from the same domain Domain definition consists of the following components
Domain Name Meaning Data type Size/ Length Allowable values or range
Entity Integrity
Primary key
Referential Integrity
Involves foreign key
Operational Constraints
Implement real world limitations
Copyright 2012 Pratian Technologies www.pratian.com
deptid
EMPLOYEE TABLE EmpNo 1 2 Name Mohan Sarvesh Sex M M DateOfBirth 01-01-1978 12-01-1980 DeptId 10 20
Properties of a Relation
Each entity or a table in a database has a unique name An entry at the intersection of each row and column is atomic. There can be no multivalued attributes in a relation Each row is unique. Each attribute or column within a table has a unique name. The sequence / arrangement of columns is insignificant The sequence / arrangement of rows is insignificant
DEPARTMENT name
EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate) Amalgamated into one as EMPLOYEE (empno, name, contractno, startdate, duedate)
EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate) The same can be kept apart using Foreign Key EMPLOYEE (empno, name, contractno) CONTRACT (contractno, startdate, duedate)
EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate) Or EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate, empno)
EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate) Amalgamated into one as EMPLOYEE (empno, name, contractno, startdate, duedate)
The same can be kept apart using Foreign Key EMPLOYEE (empno, name, contractno) CONTRACT (contractno, startdate, duedate) Map the foreign key into Employee - the key is null for employee without a contract. Incorrect Design
Copyright 2012 Pratian Technologies www.pratian.com
FK in EMPLOYEE
EMPLOYEE
Empno 10 11 Name Gordon Andrew Contract No 1 NULL
CONTRACT
Contractno StartDate DueDate
EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate) EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate, empno) Map the foreign key into Contract empno is mandatory thus never null.
FK in CONTRACT
So for 1:1 optional relationships, take the primary key from the mandatory end and add it to the optional end as a foreign key.
EMPLOYEE
Empno 10 11 Name Gordon Andrew
CONTRACT
Contractno 1
Copyright 2012 Pratian Technologies www.pratian.com
StartDate
EndDate
Empno 10
Such examples cannot be amalgamated as you could not select a primary key.
DEPARTMENT
has
EMPLOYEE
After Mapping the foll relations are produced DEPARTMENT (Deptid, name, type, location) EMPLOYEE (empno, name, Deptid)
Primary key
AUTHOR
N PUBLISHER
authorid
AUTHOR
Author_Publisher
1 PUBLISHER
authorid
PUBLISHER TABLE PUB_ID P1 NAME MCGRAW HILL CITY NEW YORK COUNTRY U.S.A
Summary
1-1 relationships Depending on the requirement of the relationship, the entities are either combined or the primary key of one entity type is placed as a foreign key in the other relation. 1-m relationships The primary key from the one side is placed as a foreign key in the many side. m-n relationships A new relation is created with the primary keys from each entity forming a composite key.
Copyright 2012 Pratian Technologies www.pratian.com
Combined, these are a composite primary key (uniquely identifies the order line)individually they are foreign keys (implement M:N relationship between order and product)
Write Customer relation for the foll. (a) CUSTOMER entity type with simple attributes
Map the foll into a relation (a) CUSTOMER entity type with composite attribute
NOTE: the domain constraint for the foreign key should NOT allow null value if DEPENDENT is a weak entity Foreign key
Again, no null value in the foreign keythis is because of the mandatory minimum cardinality
Foreign key
Map the foll ERD : an associative entity with an identifier Associative entity
Solution
Question time
Please try to limit the questions to the topics discussed during the session. Thank you.