Question: Patient Database ExerciseCreate, populate, and query a database using SQL scripts based on the following steps. Ensure that your scripts are fully executable without manual
Patient Database ExerciseCreate, populate, and query a database using SQL scripts based on the following steps. Ensure that your scripts are fully executable without manual intervention.Part : Create the Database and TablesSteps:Create Your Database with a Unique NameUse the naming convention: EHRDBYourName Replace YourName with your actual name.Example: Student Amanda Adams' database name will be EHRDBAmandaAdams.Write the Create ScriptConnect to your local SQL Server.Open a new query window in the master database.Write a script to:CREATE the new database.USE the newly created database.Define the tables and relationships based on the provided diagram.Ensure:Primary key columns use IDENTITY for autoincrementing.Foreign key constraints are correctly established.Reference: Use this guide to understand the IDENTITY feature.Sample Code Snippet for Part : Create and use the databaseCREATE DATABASE EHRDBStudentName;USE EHRDBStudentName; Create tables replace with actual table definitions based on the provided diagramCREATE TABLE Patients PatientID INT IDENTITY PRIMARY KEY, FirstName NVARCHAR NOT NULL, LastName NVARCHAR NOT NULL, DateOfBirth DATE NOT NULL;CREATE TABLE Appointments AppointmentID INT IDENTITY PRIMARY KEY, PatientID INT NOT NULL, AppointmentDate DATETIME NOT NULL, FOREIGN KEY PatientID REFERENCES PatientsPatientID; Add other tables as described in the diagram Part : Seed the Tables with DataSteps:Write a Second Script:Populate the tables with at least records per table.Make sure data in related tables eg foreign key columns match.Use meaningful and consistent data for fields such as names and dates.Hint: remember to include the USE command at the top of your script.Test Your Script:Run the script after resetting your database with the provided RESET script.Ensure that it runs without errors.Sample Code Snippet for Part : Use the databaseUSE EHRDBStudentName; Insert seed data into PatientsINSERT INTO Patients FirstName LastName, DateOfBirthVALUES John 'Doe', Jane 'Smith', Add more rows here; Insert seed data into AppointmentsINSERT INTO Appointments PatientID AppointmentDateVALUES :::: Add more rows here; Add inserts for other tables Part : Query Your DatabaseUsing your tables, write SQL queries to answer the following questions. Ensure your queries are correct and efficient. USE EHRDBStudentName; List all patients along with their insurance provider names. Find all appointments for a specific doctor eg DoctorID and include patient names and appointment dates. Get the total number of appointments each doctor has. List all prescriptions along with patient names, doctor names, and medication names. Get the total billing amount for each patient. Find all lab results for a specific patient eg PatientID including test types and results. Find all appointments scheduled within a specific date range to List all patients who have been prescribed a specific medication MedicationID Get the number of patients each insurance provider covers. Find the total number of lab tests conducted by each doctor. General TipsRun Independently. All three scripts create insert, query should run independently without requiring manual inputs.Error Handling. Test for and resolve any issues, such as foreign key violations or invalid data types.Resetting the Database. Use the provided RESET script in the "Student Resources" module to delete and recreate your database while testing.Add Data. Add records to your tables to ensure your queries return meaningful results.SubmitA script named CreateEHRDBYourNamesql to create the database and tables.A script named SeedEHRDBYourNamesql to insert at least records per table.A script named QueryEHRDBYourNamesql to answer the results from part
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
