Data Ass
Data Ass
1. Strong Entity Types: Each strong entity becomes a table. The primary key of the entity becomes
the primary key of the table.
2. Weak Entity Types: Each weak entity also becomes a table. This table includes a foreign key
referencing the primary key of the owning entity.
3. Binary 1:1 Relationship Types: For each binary 1:1 relationship, choose one of the entities
(preferably the one with total participation) and include a foreign key in its table that references
the primary key of the other entity’s table.
4. Binary 1:N Relationship Types: For each binary 1:N relationship, include a foreign key in the
table of the entity on the “N” side. This foreign key references the primary key of the entity on
the “1” side.
5. Binary M:N Relationship Types: For each binary M:N relationship, create a new table. This table
includes foreign keys that reference the primary keys of the tables of both participating entities.
The combination of these foreign keys forms the primary key of the new table.
6. Multivalued Attributes: For each multivalued attribute, create a new table. This table includes a
foreign key referencing the primary key of the table of the entity owning the attribute. The
combination of this foreign key and the multivalued attribute forms the primary key of the new
table.
Implementing :
Sure, let’s map the ER model to a relational model using the steps you provided:
1,Department
2,Doctor
Fname Mname Lname Doc id Salary Date of Dept ID Doc type Experience
joining
3,Patient
Fname Mname Lname sex age address E-date pnumber Doc id
4,Treatment
Treatment Pnumber Doc id Department Ailment Admission Discharge
ID ID date Date
5.Payment
Payment ID Treatment Test Charges Operation Blood Doctor Total
ID Charges Charges charges Charges
Code Implementation
CREATE DATABASE Art hospital
CREATE TABLE Department (ID varchar(8) primary key, name text not null, location varchar(10))
CREATE TABLE Doctor(Fname text not null, Mname text , Lname not null, ID varchar(8) primary key ,
qualification text not null, salary float check(salary >= 5000), Date of joining date , deptID varchar(8)
foreign key(deptID) references Department(ID), type text not null)
CREATE TABLE Patient(Fname text not null, Mname text , Lname text notnull, sex char check(sex = ‘M’
or sex = ‘F’), age int check(age > 0), address text , Entrydate date notnull, Pnumber varchar(8) primary
key, DocID varchar(8) foreign key(DocID) references Doctor(ID) )
CREATE TABLE Treatment (Ailment text , Admissiondate date not null, Dischargedate date not null,
TreatmentID varchar(8) primary key, Pnumber varchar(8) foreign key(Pnumber) references
Patient(Pnumber), DocID varchar(8) foreign key(DocID) references Doctor(ID), deptID varchar(8) foreign
key(deptID) references Department(ID))
CREATE TABLE Payment(ID varchar(8) primary key, TreatmentID foreign key(TreatmentID) references
Treatment(ID), Testcharges float , operationcharges float, bloodcharges float, doctorcharges float,
totalcharges float )