EX.
NO 21 SQL COMMANDS
AIM:
To write Queries for the following Questions based on the given table:
(a) Write a Query to Create a
new database in the name of
"STUDENTS".
CREATE DATABASE STUDENTS;
(b) Write a Query to Open the database "STUDENTS".
USE STUDENTS;
(c) Write a Query to create the above table called: "STU"
CREATE TABLE STU(ROLLNO INT PRIMARY KEY,NAME VARCHAR(10),
GENDER VARCHAR(3), AGE INT,DEPT VARCHAR(15),
DOA DATE,FEES INT);
(d) Write a Query to insert the row of above table into Info table.
INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);
(e) Write a Query to display all the details of the Employees from the above table 'STU'.
SELECT * FROM STU;
(f) To show all information about students of History department.
SELECT * FROM STU WHERE DEPT='HISTORY';
(g) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess
is less than 130.
UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;
h) JOINS
i) To Display max price and min price of each company.
SELECT COMPANY,MAX(PRICE),MIN(PRICE) FROM COST GROUP BY COMPANY;
ii) To display the company where the number of uniforms size is more than 2.
SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING
COUNT(*)>2;
iii) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.
SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM
UNIFORM U,COST C WHERE U.UCODE=C.UCODE;
iv) To display the company where the number of uniforms size is more than 2.
SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING
COUNT(*)>2;
v) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.
SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM
UNIFORM U,COST C WHERE U.UCODE=C.UCODE;