Class 12 SQL Practical File Guide
Class 12 SQL Practical File Guide
Foreign keys in the 'FEES' and 'ATTENDANCE' tables, referencing the 'RollNo' of the 'STUDENT' table, ensure referential integrity. They establish parent-child relationships between these tables and the 'STUDENT' table, meaning a record must exist in 'STUDENT' before entries in 'FEES' or 'ATTENDANCE' are valid. This prevents orphan records and maintains coherence within the database .
The 'TEACHER' table is structured with columns such as 'TID', 'TName', 'Subject', and 'Salary', allowing efficient organization of teacher data. 'TID' serves as a primary key ensuring each teacher is uniquely identifiable. This facilitates effective management and retrieval of teacher records. However, potential drawbacks could include the lack of contact information fields, which might limit communication ability with the teachers .
The IN clause in SQL simplifies querying by checking if a column's value is within a specified list. This reduces the need for multiple OR conditions. For the 'STUDENT' table, 'SELECT * FROM STUDENT WHERE RollNo IN (101, 103);' quickly retrieves records with specific roll numbers, enhancing query readability and execution efficiency .
The LIKE operator in SQL is used for pattern matching within string fields, offering a flexible way to filter records. In the 'TEACHER' table, 'SELECT * FROM TEACHER WHERE TName LIKE 'M%';' retrieves records where teacher names start with 'M'. While powerful for searching based on partial matches, LIKE can be inefficient on large datasets due to its demand on processing resources and potential to miss data if patterns are not well-defined .
The DELETE query removes specific records from a table based on a condition without affecting its structure, as demonstrated by 'DELETE FROM STUDENT WHERE RollNo = 102;'. It allows selective data management while preserving the table's integrity for future data use. In contrast, the DROP query eliminates the entire table along with all its data, as shown with 'DROP TABLE ATTENDANCE;'. This action is irreversible and should be used with caution to avoid data loss .
The 'ORDER BY' clause in SQL is used to sort the results of a query in either ascending or descending order based on one or multiple columns. For instance, sorting student records by 'Marks' in descending order allows educators to quickly identify top-performing students. The query 'SELECT * FROM STUDENT ORDER BY Marks DESC;' does exactly this, providing a structured, prioritized list of students from highest to lowest marks .
The 'STUDENT' table ensures data integrity by using the 'RollNo' column as a primary key. This enforces uniqueness across all entries, preventing duplicate roll numbers and ensuring each student is uniquely identifiable. Additionally, it maintains referential integrity with other tables like 'FEES' and 'ATTENDANCE' via foreign key relationships .
An UPDATE query changes existing records, ensuring data remains current and accurate. In the 'STUDENT' table, 'UPDATE STUDENT SET Marks = 90 WHERE RollNo = 101;' modifies Riya Sharma's marks. This capability is critical for correcting errors and reflecting new information, such as a re-evaluated exam score, which contributes to maintaining reliable and up-to-date data .
Aggregate functions like MIN, MAX, AVG, and SUM offer significant benefits in decision-making by providing insights such as the range of marks, average performance, and total marks obtained by all students. For instance, SELECT AVG(Marks) FROM STUDENT; calculates the average marks, aiding in assessing overall student performance. However, limitations include a loss of detailed individual data and dependency on accurate, up-to-date entries to ensure meaningful results .
The 'GROUP BY' clause in SQL collects data across multiple records and groups them into rows corresponding to columns that share common values, often used with aggregate functions. In the 'STUDENT' table, 'SELECT Section, COUNT(*) FROM STUDENT GROUP BY Section;' groups students by their section and counts the number of students in each section, providing insights into class distribution .