DBMS Lab Mini Project SQL Queries
DBMS Lab Mini Project SQL Queries
To calculate and update the FinalIA scores, the following steps are performed: First, create a view using the SELECT statement with the GREATEST and CASE WHEN functions to determine the highest and second highest test scores. The view, named "average_finder1," helps identify these values without altering the original data. Next, update the IAMARKS table using the UPDATE SET statement, where FinalIA is set as the average of the highest and second highest scores for each student. This update directly modifies FinalIA entries in the IAMARKS table .
The computation of the total number of male and female students in each semester and section utilizes SQL aggregate functions, specifically the COUNT function. The SQL query involves a SELECT statement including the COUNT function grouped by the semester, section, and gender fields. Joined tables ensure data integrity across the STUDENT, SEMSEC, and CLASS tables, while the GROUP BY clause facilitates aggregation by distinct combinations of the specified columns .
Challenges in updating FinalIA values may include ensuring concurrency control to prevent data anomalies, maintaining database consistency, and managing performance overheads due to lock contention. These can be mitigated by using transaction isolation levels to control interactions between concurrent operations, employing efficient indexing to accelerate update operations, and using batch processing techniques to minimize lock contention .
Normalizing the database schema is essential to eliminate redundancy, streamline data storage, and enhance query performance. For the College Database, normalization likely involves applying the 1st, 2nd, and 3rd normal forms. The 1st normal form ensures each table has no repeating groups or arrays, the 2nd normal form eliminates partial dependency on non-key attributes, and the 3rd normal form eradicates transitive dependency, ensuring that all data is dependent on only primary keys .
When creating a database schema for a college management system, considerations include ensuring proper entity relationships, implementing primary and foreign keys, and ensuring that cascading actions are defined for data integrity. For example, in the College Database, tables such as STUDENT, SEMSEC, CLASS, COURSE, and IAMARKS must be carefully designed with primary keys (like USN for STUDENT) and foreign keys with ON DELETE actions to maintain relational integrity. Schema must also be normalized to prevent redundancy and ensure scalability .
The ON DELETE CASCADE option in foreign key constraints ensures referential integrity by automatically deleting rows in the child table when corresponding rows in the parent table are deleted. This is significant as it prevents orphan records, maintaining consistency between related tables. In the college database schema, such as the CLASS table, if a student record is deleted from the STUDENT table, any dependent records in the CLASS table are also removed, ensuring the database remains clean and reliable .
The SQL query used to list student details in the fourth semester 'C' section involves a SELECT statement combined with JOIN operations. It selects relevant student details from the STUDENT, SEMSEC, and CLASS tables. The JOIN condition is fulfilled by matching the USN and SSID fields across these tables, ensuring the correct association of students with their semester section information. The query is structured with a WHERE clause that filters data to include only fourth semester and 'C' section students .
The concept of views is applied to handle Test1 marks by creating a query-defined virtual table using the CREATE VIEW statement. This view, named "test1," contains the USN, Test1 mark, and subcode for the student with a specific USN. Views are beneficial in SQL because they provide a way to simplify complex queries, enhance security by restricting access to underlying data, and offer a means to represent data in different perspectives without altering the actual tables .
Students in the 8th semester are categorized into 'Outstanding,' 'Average', or 'Weak' based on their FinalIA scores. If the FinalIA score is between 17 and 20, they are categorized as 'Outstanding.' If it is between 12 and 16, they are 'Average,' and if it is less than 12, they are categorized as 'Weak.' The SQL query uses a CASE WHEN clause to assign the category based on the FinalIA scores .
Effectively inserting data into large tables such as IAMARKS can be achieved through strategies like batching inserts, using prepared statements to reduce parsing overhead, and performing bulk uploads via SQL utilities that leverage batch processing. Indexing key fields can enhance retrieval performance post-insertion. Additionally, ensuring the database is properly tuned and using transaction management techniques like committing transactions at optimal points can further improve insertion efficiency .