Professional Documents
Culture Documents
Answer - Key - Test 2 SQL
Answer - Key - Test 2 SQL
Answer - Key - Test 2 SQL
1. Count(*)
2. Order by
3. Consider the table student. Write the statements to :
a. To access the database school.
USE SCHOOL;
b. To insert a new student record(127, Rajul Sharma, 21-04-2004, 460.5) to
the table student.
INSERT INTO STUDENT VALUES(127, “RAJUL”, “SHARMA”,
20040421, 460.5));
c. To change the marks to 485.5 of the student whose STID is 126.
UPDATE STUDENT SET MARKS=485.5 WHERE STID=126;
d. To add 10 marks to the students whose SNAME start with R.
UPDATE STUDENT SET MARKS=MARKS+10 WHERE SNAME
LIKE “R%”;
e. To display the STID, SNAME of all the students in the ascending order
of DOB.
SELECT STID, SNAME FROM STUDENT ORDER BY DOB ASC;
f. To add a constraint PRIMARY KEY to the column STID.
ALTER TABLE STUDENT ADD PRIMARY KEY (STID);
g. To add a column REMARKS in the table with datatype as varchar with
50 characters.
ALTER TABLE STUDENT ADD REMARKS VARCHAR(50);
h. To delete the records of the students who got marks less than 400.To
delete the primary key from the table student.
DELETE FROM STUDENT WHERE MARKS <400;
ALTER TABLE ATUDENT DROP PRIMARY KEY;
i. To delete the table student from the database.
DROP TABLE STUDENT;
4. Consider the table Teacher given below and write the output of the
following queries.
a. SELECT T_ID, NAME FROM Teacher ORDER BY NAME DESC;
T_ID NAME
6 SHYAM
7 SHIV
8 SHALAKHA
4 SAMIRA
2 SAMAN
3 RANDEEP
5 RAMAN
1 ARUNAN
DISTINCT (Department)
COMPUTER SC
HISTORY
MATHEMATICS
T_ID NAME
2 SAMAN
3 RANDEEP
8 SHALAKHA
1 ARUNAN
4 SAMIRA
5 RAMAN
7 SHIV
6 SHYAM
MAX(Date_of_join) MIN(Date_of_join)
2021-09-05 2017-03-24
NAME GENDER
RAMAN M
5. Consider the table teacher. Write SQL queries which are based on the
table: Teacher.
a. To display the records from table teacher in alphabetical order as per the name of the
teacher.
SELECT * FROM TEACHER ORDER BY NAME ASC;
b. To display Name, gender and department whose age is between 35 and 45.
SELECT NAME, GENDER, DEPARTMENT FROM TEACHER WHERE
AGE BETWEEN 35 AND 45;
c. To increase Salary of all teachers by 8000 whose salary if less than 2000.
UPDATE TEACHER SET SALARY=SALARY+8000 WHERE
SALARY<2000;
d. To add a column Remarks with character size 20 to the table Teacher.
ALTER TABLE TEACHER ADD REMARKS CHAR(20);