SQL Final Except 29
SQL Final Except 29
Aim: Create a student table and insert 10 row data. Implement the following SQL
commands on the student table: ALTER table to add new attributes/modify
data type/drop attribute; UPDATE table to modify data; ORDER By to
display data in ascending /descending order DELETE to remove tuple(s);
GROUP BY and find the min, max, sum.
● Creating Table
Source Code:
mysql> create table student (ROLLNO INT NOT NULL PRIMARY KEY,NAME
CHAR(10),Gender CHAR(10),DOB date, stream CHAR(10),PhoneNo
varchar(10),Location Char(10));
Query OK, 0 rows affected (0.30 sec)
Output:
Source Code:
mysql> insert into student
values(01,"Bhaskar","M","2006-02-05","Science",9711980876, "Delhi"),
(02,"Prince ","M","2007-03-27","Science",9711980877, "Delhi"),
(03,"Keshav","M","2006-03-06","Science",9711980879,
"Delhi"),(04,"Shreya","F","2005-01-29","Science",9711980893, "Delhi"),
(05,"Srishti","F","2005-03-20","Arts",9711975876,
"Delhi"),(06,"Aditya","M","2003-09-29","Science",9711980674, "Delhi"),
(07,"Mantsha","M","2005-12-26","Commerce",9711980353, "Delhi"),
(08,"Roshan","M","2007-12-06","Science",9711982367, "Delhi"),
(09,"Neha","F","2005-02-24","Arts",9743980876, "Delhi"),
(10,"Akansha","F","2003-02-23","Arts",9711980870, "Delhi");
Query OK, 10 rows affected (0.08 sec)
Records: 10 Duplicates: 0 Warnings: 0
Output:
● Altering Table
Source Code:
mysql> alter table student add column Percentage
float(3,2); Query OK, 0 rows affected, 1 warning (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 1
Output:
Output;
● Updating Table
Source Code:
mysql> update student set PhoneNo = 9399999999 where ROLLNO =
10; Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Output:
(Before Updating)
(After Updating)
● Dropping a Attribute
Source Code:
mysql> alter table student drop column Percentage;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
Output:
(Before Dropping)
● Order By
Source Code:
mysql> select * from student order by DOB;
Output:
● Group By
Source Code:
mysql> select min(DOB) as Min_DOB from student;
Output:
Source Code:
mysql> select max(DOB) as Max_DOB from student;
Output:
Source Code:
mysql> select count(DOB) as count_dob from student;
Output: