er diagrams simplified
DESCRIPTION
If find how to create E-R Diagrams ? Here is a Doc making things for you simple and easy .Entity Relationship Diagrams (ERDs) illustrate the logical structure of databases.I find many students find uneasiness in creating ER-Diagrams conceptually , but they understand how to create tables and columns for a Software project . Here is an approach creating to first create Tables and from tables ..ER DiagramsTRANSCRIPT
26/04/2009Ecologic Corporation , Chandigarh ,
www.ecologic.co.in 1
How to create E-R Diagrams from Database Tables ?
Ecologic Corporation Training Department Chandigarh www.ecologic.co.in
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 226/04/2009
Learning Objectives
� Conversion of an ER model to relational schemas�Entity sets, relationship sets, attributes,
redundancy removal, specialization, and aggregation
� SQL constructs to create tables and constraints
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 326/04/2009
Doing from E-R to Relational
� To create a relational database, we need a set of relational schemas.
� The first step of database design is to produce an E-R diagram that conforms to the user requirement.
� The subsequent step is to convert the E-R diagram into a collection of relational schemas, including constraints.
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 426/04/2009
Step 1 : Conversion
� For each entity set, create a corresponding relational schema.
� For each relationship set, create a corresponding relational schema.
� Convert attributes in the E-R diagram to columns (attributes) in the relational schemas.
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 526/04/2009
Entity Sets to Schemas
� A strong entity set is converted to a relation with no additional column.
� A weak entity set becomes a table that includes the primary key of the identifying strong entity set. E.g.,
payment = ( loan_number, payment_number, payment_date, payment_amount )
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 626/04/2009
Relationship Sets to Schemas� A many-to-many relationship set is
represented as a relation. Its attributes include the primary keys of the participating entity sets and the attributes of the relationship set. Example: borrower = (customer_id, loan_number )
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 726/04/2009
Removing Redundancy: One to Many or Many to One
� A many-to-one or one-to-many relationship set that is total on the many-side can be represented by adding the attributes of the relationship set plus the primary key of the “one” side to the relation that correponds to the “many” side
� Example: Instead of creating a separate relation for the relationship set account_branch, we can just add an attribute branch_name to the relation that represents the entity set account.
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 826/04/2009
The next step:Removing Redundancy : One to One
� For a one-to-one relationship set, it can be represented by the relation that corresponds to the entity set on either side after adding the attributes from the relationship set and the primary key of the entity from the other side.
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 926/04/2009
Removing Redundancy : Identifying Relationship� The schema corresponding to the
identifying relationship set linking a weak entity set to its identifying strong entity set is redundant.�Example: The payment schema already
contains the attributes that would appear in the loan_payment schema (i.e., loan_numberand payment_number).
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1026/04/2009
Composite Attributes
� Composite attributes are flattened out by creating a separate attribute for each component attribute�Example: given entity set customer with
composite attribute name with component attributes first_name and last_name, the schema corresponding to the entity set has two attributes
name.first_name and name.last_name
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1126/04/2009
Multivalued Attributes� A multivalued attribute M of an entity E is represented by a
separate schema EM� Schema EM has attributes corresponding to the primary key
of E and an attribute corresponding to the multivaluedattribute M.
� E.g.,: dependent_names of employee is represented as employee_dependent_names = ( employee_id, dname)
� Each value of the multivalued attribute maps to a tuple of a relation on schema EM.
� E.g., an employee entity with primary key 123 and dependents Jack and Jane maps to two tuples: (123, Jack) and (123, Jane).
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1226/04/2009
Representing Specialization (1)
� Method 1: �Form a schema for the higher-level entity set
�Form a schema for each lower-level entity set and include the primary key of the higher-level entity set and local attributes
schema attributesperson name, street, city customer name, credit_ratingemployee name, salary
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1326/04/2009
Representing Specialization (2)
� Method 2: �Form a schema for each entity set with all
local and inherited attributes
schema attributesperson name, street, citycustomer name, street, city, credit_ratingemployee name, street, city, salary
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1426/04/2009
Comparison of the Two Methods of Representing Specialization
� Method 1: getting information about an employee requires accessing two relations, the one corresponding to the low-level schema and the one corresponding to the high-level schema
� Method 2: If specialization is total, the schema for the generalized entity set (person) is not required to store information� Drawback: street and city may be stored redundantly
for people who are both customers and employees
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1526/04/2009
Representing Aggregation
� Create a schema containing� the primary key of the aggregated relationship
� the primary key of the associated entity set�any attributes of the relationship
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1626/04/2009
Example of Representing Aggregation
manages (employee_id, branch_name, title, manager_name)
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1726/04/2009
History of SQL� Developed as Sequel in System R project at
the IBM San Jose Research Laboratory� Renamed Structured Query Language (SQL)� Became ANSI and ISO standards:
�SQL-86, SQL-89, SQL-92, SQL:1999, SQL:2003
� Most of SQL-92 features are offered by commercial systems, plus varying feature sets from later standards and special proprietary features.
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1826/04/2009
Data Definition Language
� Defines�The schema for each relation
�The domain of each attribute� Integrity constraints
� Indexes for each relation�Security and authorization information for
each relation�The physical storage structure of each
relation on disk
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 1926/04/2009
Domain Types in SQL
� char(n), varchar(n) Fixed length or variable length character strings
� int, smallint Integers � numeric(p,d) Fixed point number � real, double precision, float(n) Floating
point and double-precision floating point numbers
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2026/04/2009
Create Table SQL Construct
create table r (A1 D1, A2 D2, ..., An Dn,(integrity-constraint1),...,(integrity-constraintk))
� r is the name of the relation�each Ai is an attribute name in the schema
of relation r�Di is the data type of values in the domain
of attribute Ai
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2126/04/2009
Example: Creating a Table
create table branch(branch_name char(15) not null,branch_city char(30),assets integer)
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2226/04/2009
Integrity Constraints in SQL
� not null� primary key (A1, ..., An )
create table branch(branch_name char(15),branch_city char(30),assets integer,primary key (branch_name))
primary key declaration on an attribute automatically ensuresnot null in SQL-92 onwards
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2326/04/2009
Drop and Alter Table Constructs� The drop table command deletes all
information about the dropped relation from the database.
� The alter table command can be used to add attributes to an existing relation:
alter table r add A Dwhere A is the name of the attribute to be
added to relation r and D is the domain of A.
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2426/04/2009
Examples of ER Diagrams
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2526/04/2009
Shopping Cart ER Diagram
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2626/04/2009
North Wind DB ER Diagram
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2726/04/2009
ER Diagrams Rules Simplified
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2826/04/2009
Guess What this diagram is Saying?
Ecologic Corporation , Chandigarh 160022, www.ecologic.co.in 2926/04/2009
Summary
� In general, each entity set or relationship set is translated into a relation.
� There are special cases, including many-to-one, one-to-many, and one-to-one relationships; identifying relationships; multi-valued and composite attributes; specialization and aggregation.
� Tables and constraints are created, altered, and dropped through SQL DDL.