0% found this document useful (0 votes)
22 views3 pages

MySQL Solutions for Class 12 Students

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

MySQL Solutions for Class 12 Students

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Class 12 Informatics Practices - Basic Problems

with Solutions

10 MySQL Problems with Solutions


1. Create a database named 'School'.
Solution:
CREATE DATABASE School;
Expected Output:
Query OK, 1 row affected (0.01 sec)

2. Create a table 'Students' with RollNo, Name, Marks.


Solution:
CREATE TABLE Students (RollNo INT PRIMARY KEY, Name VARCHAR(50), Marks INT);
Expected Output:
Query OK, 0 rows affected (0.02 sec)

3. Insert 5 records into 'Students' table.


Solution:
INSERT INTO Students VALUES (1,'Amit',90),(2,'Riya',85),(3,'Karan',70),(4,'Suma
Expected Output:
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0

4. Display all records from 'Students'.


Solution:
SELECT * FROM Students;
Expected Output:
+--------+-------+-------+
| RollNo | Name | Marks |
+--------+-------+-------+
| 1 | Amit | 90 |
| 2 | Riya | 85 |
| 3 | Karan | 70 |
| 4 | Suman | 88 |
| 5 | Pooja | 95 |
+--------+-------+-------+
5 rows in set (0.00 sec)

5. Display names of students who scored more than 80.


Solution:
SELECT Name FROM Students WHERE Marks>80;
Expected Output:
+-------+
| Name |
+-------+
| Amit |
| Riya |
| Suman |
| Pooja |
+-------+
4 rows in set (0.00 sec)

6. Update marks of 'Karan' to 75.


Solution:
UPDATE Students SET Marks=75 WHERE Name='Karan';
Expected Output:
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

7. Delete record of student with RollNo=2.


Solution:
DELETE FROM Students WHERE RollNo=2;
Expected Output:
Query OK, 1 row affected (0.00 sec)

8. Display average marks of students.


Solution:
SELECT AVG(Marks) FROM Students;
Expected Output:
+------------+
| AVG(Marks) |
+------------+
| 87.0000 |
+------------+
1 row in set (0.00 sec)

9. Display maximum and minimum marks.


Solution:
SELECT MAX(Marks), MIN(Marks) FROM Students;
Expected Output:
+------------+------------+
| MAX(Marks) | MIN(Marks) |
+------------+------------+
| 95 | 70 |
+------------+------------+
1 row in set (0.00 sec)
10. Display students in descending order of marks.
Solution:
SELECT * FROM Students ORDER BY Marks DESC;
Expected Output:
+--------+-------+-------+
| RollNo | Name | Marks |
+--------+-------+-------+
| 5 | Pooja | 95 |
| 1 | Amit | 90 |
| 4 | Suman | 88 |
| 3 | Karan | 75 |
+--------+-------+-------+
4 rows in set (0.00 sec)

Common questions

Powered by AI

The SQL command to calculate the average marks of students is SELECT AVG(Marks) FROM Students;. The expected result should be 87.0000 .

Deleting Riya's record with RollNo=2 would require using the SQL command DELETE FROM Students WHERE RollNo=2;. This would reduce the number of records in the 'Students' table and potentially alter aggregate calculations like average marks or rankings .

To insert multiple student records, use the SQL command INSERT INTO Students VALUES (...). For example, to insert records for five students, you combine them into one command: INSERT INTO Students VALUES (1,'Amit',90),(2,'Riya',85),(3,'Karan',70),(4,'Suman',88),(5,'Pooja',95);. This batch processing maximizes efficiency and should result in Query OK, 5 rows affected .

To retrieve the names of students scoring more than 80, use the SQL command SELECT Name FROM Students WHERE Marks > 80;. The expected result includes four students: Amit, Riya, Suman, and Pooja .

The SQL command to display all records from the 'Students' table is SELECT * FROM Students;. The expected output should be a table listing all students: RollNo | Name | Marks with each student's data on a new line .

To create a database named 'School', you can use the SQL command CREATE DATABASE School; and the expected outcome would be: Query OK, 1 row affected (0.01 sec).

To determine both the maximum and minimum marks, use SELECT MAX(Marks), MIN(Marks) FROM Students;. The expected outcome is a single row displaying maximum marks as 95 and minimum as 70 .

Updating Karan's marks to 75 requires the SQL statement UPDATE Students SET Marks=75 WHERE Name='Karan';. This operation changes Karan's marks from 70 to 75, impacting average calculations and relative standing among peers .

Use the SQL command SELECT * FROM Students ORDER BY Marks DESC; to sort students by marks in descending order. The output should list students starting with the highest scorer, Pooja, and continue to the lowest, Karan .

Omitting a primary key when creating a table can lead to duplicate records, compromising data integrity. It also complicates record retrieval and updates, as there are no unique identifiers to optimize query performance or ensure entity integrity, potentially causing database anomalies .

You might also like