Computer Science_24_25 2e
Computer Science_24_25 2e
queries
Rollno Name Gender Age Dept DOA Fees
1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200
(e) Write a Query to List all the tables that exists in the current database.
Sol:
mysql> SHOW TABLES;
Output:
(f) Write a Query to insert all the rows of above table into Info table.
Sol:
INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);INSERT
INTO STU VALUES (2,'Ankit','M', 21,'HISTORY','1998-03-24', 200);
INSERT INTO STU VALUES (3,'Anu','F', 20,'HINDI','1996-12-12', 300);
INSERT INTO STU VALUES (4,'Bala','M', 19, NULL,'1999-07-01', 400);
INSERT INTO STU VALUES (5,'Charan','M', 18,'HINDI','1997-06-27', 250);
INSERT INTO STU VALUES (6,'Deepa','F', 19,'HISTORY','1997-06-27', 300);
INSERT INTO STU VALUES (7,'Dinesh','M', 22,'COMPUTER','1997-02-25', 210);
INSERT INTO STU VALUES (8,'Usha','F', 23, NULL,'1997-07-31', 200);
(g) Write a Query to display all the details of the Employees from the above table 'STU'.
Sol:
Output:
(h) Write a query to Rollno, Name and Department of the students from STU
table.
Sol:
mysql> SELECT ROLLNO,NAME,DEPT FROM STU;
Program 11: To write SQL- Queries for the following Questions based on the
given table:
(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing
fessis less than 130.
Sol:
Output(After Update):
(c) Write a Query to add a new column Area of type varchar in table STU.
Sol:
mysql> ALTER TABLE STU ADD AREA VARCHAR(20);
Output:
(d) Write a Query to Display Name of all students whose Area Contains NULL.
Sol:
mysql> SELECT NAME FROM STU WHERE AREA IS NULL;
Output:
(e) Write a Query to delete Area Column from the table STU.
Sol:
mysql> ALTER TABLE STU DROP AREA;
Output:
TABLE: DEALERS
Dcode Dname
101 Sakthi Stationeries
103 Classic Stationeries
102 Indian Book House
(a) To display the total Unit price of all the products whose Dcode as 102.
Sol:
mysql> SELECT SUM(UNITPRICE) FROM STOCK GROUP BY DCODE
HAVINGDCODE=102;
Output:
(b) To display details of all products in the stock table in descending order of Stock date.
Sol:
mysql> SELECT * FROM STOCK ORDER BY STOCKDATE DESC;
Output:
(c) To display maximum unit price of products for each dealer individually as
per dcodefrom the table Stock.
Sol:
(d) To display the Pname and Dname from table stock and dealers.
Sol:
mysql> SELECT PNAME,DNAME FROM STOCK S,DEALERS D
WHERE S.DCODE=D.DCODE;
Output: