We read your photo as:
Identify the database model.
ScanSolve AI Answer
Step-by-step solution
6 stepsIdentify the database model.
Figure A, with its entities, attributes, and relationships, represents an Entity-Relationship (ER) model. Figure B shows a Relational model derived from an ER model. The question asks for the model given in the figures, implying the conceptual model.
- The database model given in the figures is the Entity-Relationship (ER) model.
Define Primary Key and provide an example.
A primary key is a column or a set of columns in a table that uniquely identifies each row in that table. It must contain unique values and cannot contain NULL values. 2. a. Primary key: A primary key is an attribute or a set of attributes that uniquely identifies each record in a table. * Example from the model:
Matriclein theDOCTORtable,SSNoin thePATIENTtable,ConsulNoin theCONSULTATIONtable,CodeSSin theMEDICATIONtable.Define Composite Key and provide an example.
A composite key is a primary key that consists of two or more attributes (columns) that uniquely identify each record in a table. 2. b. Composite key: A composite key is a primary key that consists of two or more attributes whose values, when combined, uniquely identify each record in a table. * Example from the derived relational model: In the
PRESCRIPTIONtable (which resolves the many-to-many relationship betweenCONSULTATIONandMEDICATION), the combination ofConsulNoandCodeSSwould form a composite primary key.Derive the Relational model.
Based on Figure A, the relational model is derived as follows, with primary keys marked with an asterisk (*):
3.- DOCTOR (Matricle*, Name, Surname, Qualification)
- PATIENT (SSNo*, Name, Surname)
- CONSULTATION (ConsulNo*, Date, Time, Matricle, SSNo)
Matricleis a foreign key referencingDOCTOR.SSNois a foreign key referencingPATIENT.
- MEDICATION (CodeSS*, Pharmacy, CommerceName)
- PRESCRIPTION (ConsulNo*, CodeSS*)
ConsulNois a foreign key referencingCONSULTATION.CodeSSis a foreign key referencingMEDICATION.- The combination (
ConsulNo,CodeSS) forms the composite primary key.
Create the database GHHosp.
- The SQL code to create the database
GHHospis:
CREATE DATABASE GHHosp;- The SQL code to create the database
Create all the relations (tables) for the GHHosp database.
- The SQL code to create the relations (tables) derived in Step 4 is:
USE GHHosp; CREATE TABLE DOCTOR ( Matricle VARCHAR(10) PRIMARY KEY, Name VARCHAR(50) NOT NULL, Surname VARCHAR(50) NOT NULL, Qualification VARCHAR(100) ); CREATE TABLE PATIENT ( SSNo VARCHAR(15) PRIMARY KEY, Name VARCHAR(50) NOT NULL, Surname VARCHAR(50) NOT NULL ); CREATE TABLE CONSULTATION ( ConsulNo INT PRIMARY KEY AUTO_INCREMENT, Date DATE NOT NULL, Time TIME NOT NULL, Matricle VARCHAR(10) NOT NULL, SSNo VARCHAR(15) NOT NULL, FOREIGN KEY (Matricle) REFERENCES DOCTOR(Matricle), FOREIGN KEY (SSNo) REFERENCES PATIENT(SSNo) ); CREATE TABLE MEDICATION ( CodeSS VARCHAR(10) PRIMARY KEY, Pharmacy VARCHAR(100), CommerceName VARCHAR(100) NOT NULL ); CREATE TABLE PRESCRIPTION ( ConsulNo INT NOT NULL, CodeSS VARCHAR(10) NOT NULL, PRIMARY KEY (ConsulNo, CodeSS), FOREIGN KEY (ConsulNo) REFERENCES CONSULTATION(ConsulNo), FOREIGN KEY (CodeSS) REFERENCES MEDICATION(CodeSS) );
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.