0% found this document useful (0 votes)
7 views2 pages

MySQL Database Management for Students

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

MySQL Database Management for Students

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

5.

3 Data Management

Prac 10 – Write the code in MySQL to

Q1. Create a database named ‘SMgmt’


Q2. Open this database
Q3. Create a table named ‘Student_Detail’ as per the understanding the structure of the table given as below
(Student_Id – primary key)

Student_Id Name D_O_B English Maths_Bio Phy_Acc Chem_BSt IP

101 Amitej 2000/02/01 98 78 87 77 98


102 Abhishek 2001/09/11 88 98 89 98 78
103 Bhavya 2000/12/12 88 89 88 89 88
104 Mansi 2001/07/11 83 85 87 85 83
105 Anushka 2000/02/12 77 79 77 79 81
106 Prakhar 2001/12/15 88 89 90 93 88
107 Shivam 2000/04/24 73 75 77 75 73
108 Raj Shekhar 2001/12/28 87 85 83 85 87

Q4. Insert the records as given above.

Q5. Show the average marks of each Subject.

Q6. Show the Maximum score in English.

Q7. Show the minimum score of the subject IP.

Q8. Add a new column named Scholarship and assign all the students with the constant amount 5000.00

Q9. Change the Scholarship amount to 10000.00 for all those students who have scored above 85 in
Phy_Acc and Chem_BSt.

Q10. Show the name of the students with 10% of the scholarship amount added for those students who have
scored above 90 in the Maths_Bio and the heading of this column should be Max Scholars . (** Not editing
the column just for the display purpose)

*************
Code 10

Statement1  CREATE DATABASE SMgmt;

Statement2  USE SMgmt;

Statement3 
CREATE TABLE Student_Detail
( Student_Id INTEGER(4) PRIMARY KEY ,
Name VARCHAR(20) ,
D_O_B DATE ,
ENGLISH INTEGER(3) ,
Maths_Bio INTEGER(3) ,
Phy_Acc INTEGER(3) ,
Chem_BSt INTEGER(3) ,
IP INTEGER(3) ) ;

Statement 4  INSERT INTO Student_Detail


( Student_Id , Name , D_O_B , ENGLISH , Maths_Bio , Phy_Acc , Chem_BSt , IP)
VALUES ( 101, ‘Amitej’, ‘200/02/01’, 98, 78, 87, 77, 98 ),
(102, ‘Abhishek’, ‘2001/09/11’, 88, 98, 89, 98, 78),
(103, ‘Bhavya’, ‘2000/12/12’ , 88, 89, 88, 89 ,88),


);

Query 5  SELECT Student_Id, Name, AVG(English), AVG(Maths_Bio), AVG(Phy_Acc),


AVG(Chem_BSt), AVG(IP) FROM Student_Detail;

Query 6  SELECT MAX( English) FROM Student_Detail;


Query 7  SELECT MIN(IP) FROM Student_Detail;

Query 8  ALTER TABLE Student_Detail


ADD Scholarship DECIMAL(10,2)
DEFAULT 5000.00;

Query 9  UPDATE Student_Detail


SET Scholarship = 10000.00
WHERE Phy_Acc > 85 AND Chem_BSt >85;

Query 10  SELECT Name, Scholarship*0.1+Scholarship AS Max Scholars


FROM Student_Detail
WHERE Maths_Bio > 90;

************

Common questions

Powered by AI

To display additional computed columns in the query results without altering the table structure, you can create calculated columns directly in the SELECT statement. For example, 'SELECT Name, Scholarship*0.1 + Scholarship AS Max Scholars FROM Student_Detail WHERE Maths_Bio > 90;' creates a computed column 'Max Scholars' to show 10% additional scholarship amount for students scoring above 90 in 'Maths_Bio'.

To update a specific field based on criteria in other fields, use the 'UPDATE' statement with a 'WHERE' clause to specify the conditions. For example, 'UPDATE Student_Detail SET Scholarship = 10000.00 WHERE Phy_Acc > 85 AND Chem_BSt > 85;' updates the 'Scholarship' field to 10000.00 for students scoring above 85 in both 'Phy_Acc' and 'Chem_BSt'.

The process for inserting multiple records into a database table in one execution involves using a single 'INSERT INTO' statement with multiple value tuples. For example, 'INSERT INTO Student_Detail (Student_Id, Name, D_O_B, ENGLISH, Maths_Bio, Phy_Acc, Chem_BSt, IP) VALUES (101, 'Amitej', '2000/02/01', 98, 78, 87, 77, 98), (102, 'Abhishek', '2001/09/11', 88, 98, 89, 98, 78);' inserts multiple student records at once.

The SQL command to identify the maximum score in a specific subject column is 'SELECT MAX()', followed by the column name. For example, 'SELECT MAX(English) FROM Student_Detail;' is used to find the highest score in the 'English' subject.

To create and use a new database named 'SMgmt' for managing student details, the following steps are required: 1) Create the database using the command 'CREATE DATABASE SMgmt'; 2) Use the newly created database with 'USE SMgmt'; 3) Create a table 'Student_Detail' with necessary fields and constraints, such as making 'Student_Id' a primary key.

To determine the lowest score achieved in the 'IP' subject, use the 'SELECT MIN()' function. For example, 'SELECT MIN(IP) FROM Student_Detail;' retrieves the minimum score from the 'IP' column in the 'Student_Detail' table.

To ensure a column acts as a unique identifier for each record, declare it as a 'PRIMARY KEY' when creating or altering the table. For instance, in the table 'Student_Detail', 'Student_Id' is defined as 'INTEGER(4) PRIMARY KEY', making it a unique identifier for each student.

Calculated fields in a SELECT statement are used to perform operations on data on-the-fly without altering the table structure. Advantages include the ability to derive insights directly from queries, reduce the need for additional storage for pre-calculated values, and dynamically generate data views based on current data, such as adding conditional bonuses to scholarship amounts for reporting purposes.

To calculate the average marks for multiple subjects in a MySQL database, you can use the 'SELECT' statement with the 'AVG()' function for each subject column. For instance, the query 'SELECT AVG(English), AVG(Maths_Bio), AVG(Phy_Acc), AVG(Chem_BSt), AVG(IP) FROM Student_Detail;' calculates the average marks for the subjects 'English', 'Maths_Bio', 'Phy_Acc', 'Chem_BSt', and 'IP'.

To add a new column to a table and set a default value for all existing records, you use the 'ALTER TABLE' command. For example, 'ALTER TABLE Student_Detail ADD Scholarship DECIMAL(10,2) DEFAULT 5000.00;' will add a column 'Scholarship' with a default value of 5000.00 for all existing records in 'Student_Detail'.

You might also like