SQL Database Setup for Adult Literacy
SQL Database Setup for Adult Literacy
Enforcing data types and constraints ensures that data meets specified conditions, enhancing reliability and integrity within the 'AdultLiteracy' database. For instance, integer types for IDs prevent invalid entries, date types ensure valid date formats, and CHECK constraints restrict permissible values for fields like 'Subject'. These rules prevent erroneous, inconsistent, or out-of-scope data from entering the system, thereby maintaining accurate and trustworthy datasets .
Using a single 'Subject' column with a CHECK constraint limits each tutor to one subject per record, complicating scenarios where tutors need to teach multiple subjects. This constraint restricts flexibility and could result in duplicated entries or the need for workarounds like composite keys or arrays. To address this, the schema could be modified to allow lists or arrays in the 'Subject' column, or create an associative table to relate tutors with multiple subjects, though these solutions introduce complexity in data management and querying .
The composite primary key in the 'TutorReport' table, consisting of 'MatchID' and 'Month', ensures each report entry is unique per tutoring session and month. This key prevents duplicate reports for the same tutor and match in any given month, thus maintaining precise and non-redundant reporting data .
The SQL command to identify tutors who haven't submitted a report for July is: SELECT tut.TutorID, tut.CertDate, tut.Status, tut.Subject FROM Tutor tut WHERE NOT EXISTS (SELECT * FROM MatchHistory MatchHis JOIN TutorReport TutRep ON MatchHis.MatchID = TutRep.MatchID WHERE tut.TutorID = MatchHis.TutorID AND Month='7/08'). The logic behind this query is to select tutors from the 'Tutor' table whose 'TutorID' is not present in any 'TutorReport' records for July, ensuring only those without submissions in July are retrieved .
Defining a composite primary key on the 'Tutor' table allows a tutor to have multiple records, each associated with a different subject. By using a composite key consisting of 'TutorID' and 'Subject', a tutor can sign up to teach both 'Reading' and 'Math', for instance, by having separate entries in the table for each subject, while maintaining their unique identification through the combined key .
Adding a 'Math_score' column to the 'STUDENT' table provides detailed performance data specific to math, permitting refined analysis of student abilities and progress. This enhancement allows for targeted educational strategies and can improve the overall utility of the database by enabling queries that specifically evaluate and track math proficiency across students .
Data consistency between the 'Student' and 'MatchHistory' tables is ensured by using primary and foreign keys. The 'StudentID' in 'Student' serves as a primary key, while in 'MatchHistory', it acts as a foreign key. This relationship enforces that all entries in 'MatchHistory' must reference an existing student in 'Student', ensuring that matches cannot be created for non-existent students and maintaining consistent data across tables .
Using an array or list for the 'Subject' column allows storing multiple subjects for a single tutor without altering the primary key structure. This approach simplifies querying for tutors with multiple subjects. However, it may complicate data integrity enforcement and require additional checks to ensure values conform to allowed subjects ('Reading', 'Math', 'ESL'). Array handling can also make SQL operations less efficient compared to normalized designs .
Foreign key constraints in the 'MatchHistory' table ensure that each 'TutorID' and 'StudentID' in a match record references existing entries in the 'Tutor' and 'Student' tables, respectively. This guarantees that all matches involve valid tutors and students, preventing orphaned records and maintaining referential integrity across tables .
Altering the 'Tutor' table to include 'English' as a subject in the 'Subject' column would violate the CHECK constraint, leading to errors as the constraint ensures data integrity by allowing only specified subjects. This change would necessitate modifying the constraint to include 'English', ensuring that new data aligns with the allowed values, thus maintaining integrity and reducing the likelihood of erroneous data entries .