i've made a sql to a data base project, i will give the project then the code and find the mistakes ABC Training Center
ABC is a training center that conducts various training courses. Each course is identified by a course no, title, units, level, and subject. Courses are conducted by instructors, who can be full time or part time. Instructors are identified by an identifier, name, mobile phone number, email, address comprising of street name, city and country, and specialty. An instructor’s employment status is determined at the time of appointment. Part time instructors work a number of hours each month and are paid according to a pay rate, which must be greater than 20, determined by the training center. Full time instructors have monthly salaries. In certain circumstances, full time instructors may be assigned additional training courses besides to their training load and they are paid as part time instructors. An instructor can train a group of students in one course for each training period. The same course may be conducted by several instructors at the same training periods. Each year is divided into 4 training periods. The starting and ending dates describe a training period. A student, described by an id, student number, name, address, at least one email, and age, may participate in up to 3 training courses per period. Students' information may be queried using first and last names.
The project consists of four phases:
In this phase, you are to develop an Enhanced Entity-Relationship (EER) diagram using UML notation for the database based on the information provided. If there are ambiguities, you must resolve them and state your assumptions. The EER diagram must conceptually model the data requirements of the enterprise.
Logical Design Phase In this phase, you must map the EER diagram into a set of relations with minimal nulls. Show primary keys and identify foreign keys.
Relations Normalization Phase In this phase, you must normalize your relational database design to the 3NF.
Database Implementation Phase In this phase, write SQL DDL statements that can be used to create the tables for the relations you obtained from phase (3) with sample data (an average of 3 rows per table). Write an SQL statement to list all instructors who are full time and worked on a part time basis in alphabetical order of names. Write an SQL statement to list all student names and their completed courses. CREATE TABLE Course ( CourseNo INT PRIMARY KEY, Title VARCHAR(255), Units INT, Level VARCHAR(50), Subject VARCHAR(100) );
CREATE TABLE Instructor ( ID INT PRIMARY KEY, Name VARCHAR(255), Mobile VARCHAR(20), Email VARCHAR(255), Address VARCHAR(255), Specialty VARCHAR(100), EmploymentStatus VARCHAR(20) );
CREATE TABLE Student ( ID INT PRIMARY KEY, StudentNo INT, Name VARCHAR(255), Address VARCHAR(255), Email VARCHAR(255), Age INT );
CREATE TABLE TrainingPeriod ( StartDate DATE PRIMARY KEY, EndDate DATE );
CREATE TABLE Teaches ( InstructorID INT, CourseNo INT, TrainingPeriod DATE, PRIMARY KEY (InstructorID, CourseNo, TrainingPeriod), FOREIGN KEY (InstructorID) REFERENCES Instructor(ID), FOREIGN KEY (CourseNo) REFERENCES Course(CourseNo), FOREIGN KEY (TrainingPeriod) REFERENCES TrainingPeriod(StartDate) );
CREATE TABLE Enrolls ( StudentID INT, CourseNo INT, TrainingPeriod DATE, PRIMARY KEY (StudentID, CourseNo, TrainingPeriod), FOREIGN KEY (StudentID) REFERENCES Student(ID), FOREIGN KEY (CourseNo) REFERENCES Course(CourseNo), FOREIGN KEY (TrainingPeriod) REFERENCES TrainingPeriod(StartDate) ); -- Create the Instructor table CREATE TABLE Instructor ( ID INT PRIMARY KEY, Name VARCHAR(100), Mobile VARCHAR(20), Email VARCHAR(100), Address VARCHAR(100), Specialty VARCHAR(50), EmploymentStatus VARCHAR(20) );
-- Insert sample data into the Instructor table INSERT INTO Instructor VALUES (1, 'Instructor1', '123-456-7890', '[email protected]', '123 Main St, City, Country', 'Specialty1', 'Full Time'); INSERT INTO Instructor VALUES (2, 'Instructor2', '987-654-3210', '[email protected]', '456 Oak St, City, Country', 'Specialty2', 'Part Time'); INSERT INTO Instructor VALUES (3, 'Instructor3', '555-123-4567', '[email protected]', '789 Pine St, City, Country', 'Specialty3', 'Full Time');
-- Create the Student table CREATE TABLE Student ( ID INT PRIMARY KEY, StudentNo INT, Name VARCHAR(100), Address VARCHAR(100), Email VARCHAR(100), Age INT );
-- Insert sample data into the Student table INSERT INTO Student VALUES (1, 1001, 'Student1', '101 Ram, City, Country', '[email protected]', 20); INSERT INTO Student VALUES (2, 1002, 'Student2', '202 Lakman, City, Country', '[email protected]', 22); INSERT INTO Student VALUES (3, 1003, 'Student3', '303 Sita, City, Country', '[email protected]', 25);
-- Create the TrainingPeriod table CREATE TABLE TrainingPeriod ( StartDate DATE PRIMARY KEY, EndDate DATE );
-- Insert sample data into the TrainingPeriod table INSERT INTO TrainingPeriod VALUES ('2023-01-01', '2023-04-01'); INSERT INTO TrainingPeriod VALUES ('2023-04-02', '2023-07-01'); INSERT INTO TrainingPeriod VALUES ('2023-07-02', '2023-10-01');
-- Create the Teaches table CREATE TABLE Teaches ( InstructorID INT, CourseNo INT, StartDate DATE, EndDate DATE, PRIMARY KEY (InstructorID, CourseNo, StartDate, EndDate), FOREIGN KEY (InstructorID) REFERENCES Instructor(ID), FOREIGN KEY (CourseNo) REFERENCES Course(CourseNo), FOREIGN KEY (StartDate, EndDate) REFERENCES TrainingPeriod(StartDate, EndDate) );
-- Insert sample data into the Teaches table INSERT INTO Teaches VALUES (1, 1, '2023-01-01', '2023-04-01'); INSERT INTO Teaches VALUES (2, 2, '2023-04-02', '2023-07-01'); INSERT INTO Teaches VALUES (3, 3, '2023-07-02', '2023-10-01');
-- Create the Enrolls table CREATE TABLE Enrolls ( StudentID INT, CourseNo INT, StartDate DATE, EndDate DATE, PRIMARY KEY (StudentID, CourseNo, StartDate, EndDate), FOREIGN KEY (StudentID) REFERENCES Student(ID), FOREIGN KEY (CourseNo) REFERENCES Course(CourseNo), FOREIGN KEY (StartDate, EndDate) REFERENCES TrainingPeriod(StartDate, EndDate) );
-- Insert sample data into the Enrolls table INSERT INTO Enrolls VALUES (1, 1, '2023-01-01', '2023-04-01'); INSERT INTO Enrolls VALUES (2, 2, '2023-04-02', '2023-07-01'); INSERT INTO Enrolls VALUES (3, 3, '2023-07-02', '2023-10-01');
There are several issues and potential corrections that need to be made to the SQL provided:
Duplicate Instructor
table creation: The CREATE TABLE Instructor
statement appears twice. The second one should be removed to avoid an error if this script is executed.
Address column structure: The description of the instructor and student address contains street name, city, and country. These should be in columns for normalization and ease of query.
The TrainingPeriod
table only has start date as the primary key, which might not be unique enough if two training periods start on the same day in different years. It would be more accurate to have a composite key that includes both StartDate
and EndDate
, or preferably a separate PeriodID
.
Foreign key reference issues in Teaches
and Enrolls
: The to the TrainingPeriod
table should include both StartDate
and EndDate
. Additionally, there's an assumption here that a combination of StartDate
and EndDate
would uniquely identify a training period, which is not established by the current table structure.
Payment details for part-time and full-time instructors: There are no columns to store the number of hours worked by part-time instructors, the pay rate, or the monthly salary for full-time instructors.
Full time instructors having part-time assignments: There is no structure to capture the additional part-time assignments for full-time instructors.
7 Lack of course completion status for students: There is no table or column to store whether a student has completed a course.
Considering the above points, the SQL data definitions might be revised to include additional attributes and constraints, such as:
CREATE TABLE Instructor ( ID INT PRIMARY KEY, Name VARCHAR(255), Mobile VARCHAR(20), Email VARCHAR(255), StreetName VARCHAR(), City VARCHAR(255), Country VARCHAR(255), Specialty VARCHAR(100), Status VARCHAR(20), PartTimeHours INT, -- Assuming part-time worked PartTimePayRate DECIMAL(7,2), -- Assuming pay for part-time work MonthlySalary DECIMAL(7,2) -- Assuming salary for full-time instructors -- Other columns and constraints as necessary ); -- Other table definitions would be similarly updated. CREATE TABLE TrainingPeriod ( PeriodID INT AUTO_INCREMENT PRIMARY KEY, StartDate DATE, EndDate DATE -- Unique or check constraints to ensure no overlapping periods ); -- Update foreign key references in Teaches and Enrolls CREATE TABLE Teaches ( -- Other columns as before TrainingPeriodID INT, -- Assuming change to PeriodID -- Foreign key references updated to reflect this ); -- Create a new attribute or table to track course completions for students, etc.
Finally, regarding the SQL statements requested in the implementation phase, the specific statement would depend on the full structure of the database, including these necessary corrections. Here’s an example of what one of those statements might look like with the corrected schema:
SQL to list all instructors who are full time and worked on a part-time basis:
SELECT DISTINCT I.Name FROM Instructor I JOIN Teaches T ON I.ID =.InstructorID WHERE I.EmploymentStatus = ' Time' AND I.PartTimeHours > 0 ORDER BY I.Name;
Please note that without knowing the exact structure intended for tracking whether full-time instructors worked as part-time (such as a separate table logging part-time assignments) this statement is based on the assumption that the PartTimeHours
column is used to store hours worked in part-time capacity.
python4csip.com
freecodecamp.org
geeksforgeeks.org