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 1: Create the Database and TablesSteps:Create Your Database with a Unique NameUse the naming convention: EHR_DB_[YourName]. Replace [YourName] with your actual name.Example: Student Amanda Adams' database name will be EHR_DB_AmandaAdams.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(1,1) for auto-incrementing.Foreign key constraints are correctly established.Reference: Use this guide to understand the IDENTITY feature.Sample Code Snippet for Part 1:-- Create and use the databaseCREATE DATABASE EHR_DB_StudentName;USE EHR_DB_StudentName;-- Create tables (replace with actual table definitions based on the provided diagram)CREATE TABLE Patients ( PatientID INT IDENTITY(1,1) PRIMARY KEY, FirstName NVARCHAR(50) NOT NULL, LastName NVARCHAR(50) NOT NULL, DateOfBirth DATE NOT NULL);CREATE TABLE Appointments ( AppointmentID INT IDENTITY(1,1) PRIMARY KEY, PatientID INT NOT NULL, AppointmentDate DATETIME NOT NULL, FOREIGN KEY (PatientID) REFERENCES Patients(PatientID));-- Add other tables as described in the diagram Part 2: Seed the Tables with DataSteps:Write a Second Script:Populate the tables with at least 20 records per table.Make sure data in related tables (e.g., 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 2:-- Use the databaseUSE EHR_DB_StudentName;-- Insert seed data into PatientsINSERT INTO Patients (FirstName, LastName, DateOfBirth)VALUES ('John', 'Doe', '1985-03-15'),('Jane', 'Smith', '1990-07-22'),-- Add 18 more rows here;-- Insert seed data into AppointmentsINSERT INTO Appointments (PatientID, AppointmentDate)VALUES (1,'2024-01-1010:00:00'),(2,'2024-01-1114:30:00'),-- Add 18 more rows here;-- Add inserts for other tables Part 3: Query Your DatabaseUsing your tables, write SQL queries to answer the following questions. Ensure your queries are correct and efficient. USE EHR_DB_StudentName; --1. List all patients along with their insurance provider names. --2. Find all appointments for a specific doctor (e.g., DoctorID =1)-- and include patient names and appointment dates. --3. Get the total number of appointments each doctor has. --4. List all prescriptions along with patient names, doctor names, -- and medication names. --5. Get the total billing amount for each patient. --6. Find all lab results for a specific patient (e.g., PatientID =1)-- including test types and results. --7. Find all appointments scheduled within a specific date range --(2024-01-01 to 2024-12-31).--8. List all patients who have been prescribed a specific medication --(MedicationID =1).--9. Get the number of patients each insurance provider covers. --10. 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 Create_EHR_DB_[YourName].sql to create the database and tables.A script named Seed_EHR_DB_[YourName].sql to insert at least 20 records per table.A script named Query_EHR_DB_[YourName].sql to answer the 10 results from part 3.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!