Question 3 refers to the relational database with a schema described below:
The hospital database contains information about the treatments of patients performed by the doctors. The database also contains information on the prescriptions ordered by the doctors. The schemas of relational tables, the meanings of attributes and specifications of primary, candidate, and foreign keys are given below.
HOSPITAL HospitalCd Name Address Estate PostalCode EstablishedDate |
Hospital Code Name of the hospital Address of the hospital The estate where the hospital is located The postal code of the address The date the hospital was established |
Primary key = HospitalCd |
|
DOCTOR DoctorId Name Citizenship WorkFor |
The identification number of the doctor Name of the doctor The citizenship of the doctor The hospital the doctor is working for |
Primary key = DoctorId Foreign key = WorkFor references HOSPITAL (HospitalCd) |
|
PATIENT NRIC Name DateOfBirth Sex Address Estate PostalCode |
The NRIC of the patient The name of the patient The birth date of the patient The gender of the patient The residential address of the patient The estate where the patient lives The postal code of the address |
Primary key = NRIC |
|
TREATMENT DoctorId NRIC TreatmentDate Description |
The doctor identification number The NRIC of the patient The treatment date Description of the treatment |
Primary key = (DoctorId, NRIC, TreatmentDate) Foreign key = (DoctorId) references DOCTOR(DoctorId) Foreign key = (NRIC) references PATIENT(NRIC) |
|
PRESCRIPTION DoctorId NRIC TreatmentDate ItemNum Drug Dosage |
The doctor identification number The NRIC of the patient The treatment date The item number of the prescription The drug prescribed by the doctor The dosage prescribed |
Primary key = (DoctorId, NRIC, TreatmentDate, ItemNum) Foreign key = (DoctorId, NRIC, TreatmentDate) references TREATMENT(DoctorId, NRIC, TreatmentDate)
(6.0 marks)
|
--//SQL FUNCTION//
--//WHICH WILL RETURN NRIC'S OF PATIENT WHO HAVE 3 OR MORE TREATMENTS FROM SAME DOCTOR this function will accept one doctor id as an parameter to return NRIC's based on this id//
GO
CREATE FUNCTION PATIENT(@DoctorId NVARCHAR)
RETURNS TABLE
AS
RETURN SELECT PATIENT.NRIC from PATIENT
inner join TREATMENT on patient.NRIC=TREATMENT.NRIC
inner join
DOCTOR on TREATMENT.DoctorId=@DoctorId
where (select
COUNT(NRIC) from PATIENT)>=3
--//SQL PROCEDURE TO INSERT VALUES INTO DOCOTOR TABLE IF HOSPITAL CODE PATTEREN IS (H__) means if first letter of code is H and then code have two more digits then new record will be inserted into DOCOTR table.//
GO
CREATE PROCEDURE NewDoctor(@DoctorId nvarchar(200), @Name
nvarchar(200),
@Citizenship nvarchar(200), @WorkFor nvarchar(200))
AS
BEGIN
IF(@WorkFor like('H__'))
BEGIN
INSERT INTO DOCTOR VALUES(@DoctorId, @Name, @Citizenship,
@WorkFor)
END
ELSE
BEGIN
SELECT 'insertion falied due to code patteren!'
END
END
--//COMMENT DOWN FOR ANY QUERIES...
--//HIT A THUMBS UP IF YOU DO LIKE IT!!!
Question 3 refers to the relational database with a schema described below: The hospital database contains...
Consider the following relational database schema- Doctor(SSN,FirstName,LastName,Speciality,YearsOfExperience,PhoneNum) Patient(SSN,FirstName,LastName,Address,DOB,PrimaryDoctor_SSN) Medicine(TradeName,UnitPrice,GenericFlag) Prescription(Id,Date,Doctor_SSN,Patient_SSN) Prescription_Medicine(Prescription_Id,Trade_Name,NumOfUnits) Write Relational Algebra expression for the following: List the first and last name of patients whose primary doctor named “Rahul kumar” List the first and last name of doctors who are not primary doctors of any patient List the first and last name of patients who have no prescription written by doctors other than the primary doctors List the trade name of generic medicine with unit price greater than...
Part I. Mapping an (E)ER schema to a relational database schema (46 points) NOTE o Each relation sachem should have a primary key (PK) when you answer. • To present the reference table of the foreign key (e.g., FK, FK1, K2), use an arrow. Do not use the relationship cardinality symbols of crow's foot notation in the relational database schema. o It is not required to specify the domain constraint (e.g., data type and length) of each attribute. 1. (12...
3. (20 POINTS) Consider the LIBRARY relational database schema below to write down the relational algebra expressions for the following two queries. No SQL statements are required. BOOK Bookid Title Publisher name BOOK AUTHORS Book id Author name PUBLISHER Name Address Phone BOOK COPIES Book d Branch Id No o copies BOOK LOANS Book Branch Id Card no Date out Due date LIBRARY BRANCH Branch Branch name Address BORROWER Card Name Address Phone 3.A.) (10 POINTS) Let the number of...
Assume that you are working with a hospital and this hospital needs a software system to track its patients’ information. Your role in this software development is to design the database. There are many aspects of such a hospital software system to develop. However, in this assignment, you will only address interactions between doctors and patients. Your first step will be to create the relations necessary for this system and identify and describe the constraints that would be appropriate for...
Lab 7 In the “Care One” hospital each patient is assigned to just one doctor. Each doctor can visit many or zero patients. The following image illustrates a small part of this hospital. Please create a schema with name of “careone”, then add these two tables. You should insert 4 doctors and 6 patients in this database (just mockup information). All of the creations and insertions should be done by writing queries. The queries should contain the Data Definition, constraints,...
The relational schema shown below is part of a student database. The primary and foreign keys are highlighted in bold.Student (studNo, studName, address, mobileNo)Course (courseNo, courseName, creditHour, level) Registration (studNo, courseNo, regDate, semester, session)Project (projNo, projName, courseNo)Assignment (projNo, studNo, startDate, dueDate, hoursSpent)Write SQL queries based on the student database given above: 1. Create tables & constraints for the student database.2. Insert some data into the tables to check that the tables created are correct. No limit on how many rows you want...
Question: Use the technique of normalization to validate the structure of your relational schema. Demonstrate that each of your relations is in third normal form (3NF) by displaying the functional dependencies between attributes in each relation. Note, if any of your relations are not in 3NF, this may indicate that your ER model is structurally incorrect or that you have introduced errors in the process of deriving relations from your model. The Relational Schema is as follows: Department (deptName, phone,...
SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...
database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED BELOW CREATE TABLE Department ( DECIMAL(5) VARCHAR(30) CHAR(5) DATE NOT NULL NOT NULL NOT NULL * Department number /*Department name * Department manager number */ /Manager start date DNumber DName Manager MSDate CONSTRAINT Department_PK PRIMARY KEY(DNumber) CONSTRAINT Department_CK UNIQUE(DName) CREATE TABLE DeptLocation DECIMAL(5) VARCHAR(50) NOT NULL NOT NULL DNumber * Department number */ * Department location */ Address CONSTRAINT DeptLocation_PK PRIMARY KEY(DNumber, Address) CONSTRAINT...
Consider the following relational database to manage concert and ticket sales. The relations are artist, concert, venue, seat, ticket, and fan. The schemas for these relations (with primary key attributes underlined) are: Artist-schema = (artistname, type, salary) Concert-schema = (artistname, date, venuename, artistfees) Venue-schema = (venuename, address, seating_capacity) Seat-schema=(venuename, row, seatnumber) Ticket-schema = (fanID, date, venuename, row, seatnumber) Fan-schema = (fanID, name, address, creditcardno) Where: • artistname is a unique name for the artist (because of trademark/copyright rules no two...