0% found this document useful (0 votes)
31 views

SQL commands

The document contains SQL queries for various tables including Emp, Student, Item, and Employee, detailing operations such as displaying, inserting, updating, and deleting records. It also includes commands to manipulate data based on specific conditions, such as filtering by house color or salary. Additionally, there are questions regarding the structure of tables and data types for attributes.

Uploaded by

Sri Vishnusaran
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

SQL commands

The document contains SQL queries for various tables including Emp, Student, Item, and Employee, detailing operations such as displaying, inserting, updating, and deleting records. It also includes commands to manipulate data based on specific conditions, such as filtering by house color or salary. Additionally, there are questions regarding the structure of tables and data types for attributes.

Uploaded by

Sri Vishnusaran
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Q1.

Write the queries for the following table : Emp

1. Display the salary of all the employees after incrementing by Rs. 1000
Ans: Select Salary+1000 from Emp;
2. Display the Employee id and slary of all the employees after decreasing by Rs.500
Ans: Select Emp_id, Salary-500 from Emp;
3. Display the Name and Salary of all the employees after incrementing it as thrice the
amount of present salary.
Ans: Select Ename, Salary*3 from Emp;
4. Display the Employee id, name, salary of all the employees after decrementing it as
half the amount of present salary
Ans:Select Emp_id, Ename, salary/2 from Emp;
5. Display the Employee id and name of all the employees
Ans:Select emp_id, ename from emp;

Q2. Write the queries for the following table :Student

1. Display the entire table


Ans : Select * from student;
2. Display the list of students whose house color is blue
Ans: Select * from Student where house=”blue”;
3. Display the admission number of students whose house color is green
Ans : Select admno from student where house=”yellow”;
4. To view records in ascending order of admission number
Ans: Select * from student order by admno asc;
5. Display the records of Class 10 students
Ans : Select * from students where class =10;
Q.3 Which command is used for the following task in database

1. To insert a new record


2. To modify the existing data

3. To delete a record

4. To display record

Ans :
1. Insert

2. Update

3. Delete

4. Select

Q4. Write the queries for the following table : Item

Itemno Iname Price Qty


12 Pen 10 17
13 Eraser 5 15
14 Notebook 15 20
1. W rite a query to insert a new reco rd of following deta ils
15, PENCIL,20,10
Ans. Insert into Item values(15,"Pencil", 20, 10);
2. W rite a query to display detail of items whose quantity is more than 10.
Ans. Select * from Item where Qty > 10;
3. Write a q ue r y to ch ange the qu a nti ty of I tem nu m be r 13 to 25.
Ans. Update Item set Qty = 25 where ltemno = 13
4. Display the total amount o feach item. The amount must be calculated as the
price multiplied by queantity for each item
Ans. Select Price * Qty from Item.
5. Di spl ay the na me of item wh ose pri ce i s 10.
Ans. Select lname from Item where price = 10

6. Di spl ay a l l the record s i n ascen d i n g order of price.


Ans. Select * from Item order by Price asc;
Q20. Consider the following ta ble: STUDENT [C.B.S.E . - 2021]

ADM NO NAM E GRADE DOB MARKS HOUSE GEN DER


1001 RU PAL 9 10/04/2006 76 GREEN M
1002 RASH Ml 9 08/12/2005 87 RED F
1003 ARN AV 10 25/05/2004 81 GREEN M
1004 SUMONA 9 23/08/2005 68 RED F
1005 ARU N 9 16/07/2005 72 GREEN M
1006 TIA 9 22/09/2005 91 BLU E F
1007 ROSH AN 10 26/08/2004 89 BLU E M

Write SQL Commands:


1. To Display the details of all students of Green House.
Ans. Select * from STUDENT where HOUSE = "GREEN";
2. To increase the marks by 5 whose ADMNO is 1005.
Ans. Update STUDENT set MARKS = MARKS + 5 where ADMNO = 1005;
3. To display the details of all students whose MARKS are less than 80.
Ans. Select * from STUDENT where MARKS < 80;
4. Display the list of all students in descending order of MARKS
Ans. Select * from STUDENT order by MARKS;

Q21. Identify any two Column name/Attr ibute a nd their data types from a given table:
PLAYER. [C.B.S.E.]

PID PNAME RUNS GENDER DOB

P101 SACHIN 13000 M 10/04/2001


P102 KAPIL 7000 M 12/02/1998
P103 SAURABH 12000 M 13/04/2001
P104 VIRAT 12500 M 17/03/2005
Ans. Column Name and it's data types are:

Column Name Data type

PIO Char
PNAME VARCHAR
Q22. Consider the following table: EMPLOYEE [C.B.S.E.]

EMPID NAME SALARY DOJ COMM DEPT GENDER

1001 ROHAN 7000 10/04/2006 300 SALES M


1002 RISHU 12000 08/12/200 100 FINANCE F
5 SALES M
1003 DEVAN SH 9000 25/05/2004 500
1004 SUMAN 10000 23/08/2005 300 MARKETI NG F
1005 ARVAN 11000 16/07/2005 500 SALES M
1006 TAMA N NA 15000 22/09/2005 200 FINANCE F
1007 ROHIT 8000 26/08/2004 900 SALES M
Write SQL Commands :

1. To display the details of all employees of SALES Department.


Ans.Select * from EMPLOYEE where DEPT = "SALES";

2. To increase the SALARY by 1000 whose EMPID is 1007.


Ans.Update EMPLOYEE set SALARY = SALARY + 1000 where EMPID = 1007;
3. To display the details of all employees whose SALARY is more than 10000-
Ans.Select * from EMPLOYEE where SALARY > 10000;
4. To display the list of all employeesin descending order of SALARY-
Ans.Select * from EMPLOYEE order by SALARY;
Q23. Consider the following ta ble: Sa les [Sam ple Paper-2022]

Sale_ld Prod_Name Price Discount

1101 Laptop 65000 2500


1103 Pen Tab 29500 1000
1105 Desktop 50000 1550
1106 Printer 12000 2000
1. Howmany fields and records are there in Sales table?
Ans. 1. There are 4 fields and 4 records in table:Sales

Write SQL commands for the following:


2. Display Sales ID and price of all products whose discount is more than
1000.
Ans: SELECT sale_Id, Price from Sales where discount>1000;
3. Display the details alphabetically by product name.
Ans : Select * from Sales order by Prod_name;

4. Display product name and sales price after deducting the discount from
the price. Note:Sales price can be calculated as (price-discount)
Ans : Select prod_name, price-Discount as Price from Sales;
Consider the following table: Teachers

NUMBER NAME AGE SUBJECT DATEOFJOIN SALARY GENDER

1 JUGAL 34 COMPUTER 10/01/201 12000 M


9
2 PRATIGYA 31 SCIENCE 24/03/2019 20000 F

3 SANDEEP 32 MATHS 12/12/2019 30000 M

4 SANGEETA 3S SCIENCE 01/07/2020 40000 F


s SATTI 42 MATHS OS/09/2020 2SOOO M

6 SHYAM so SCIENCE 27/06/2021 30000 M

7 SHIV OM 44 COMPUTER 2S/02/2021 21000 M

8 SHALAKHA 33 MATHS 31/07/2020 20000 F


a. To show all the information about IT teachers.
b. To list the details of all the teachers who are getting salary between
20000 to 35000.
c. To display the subject of all the teachers whose age is more than 40
years.
d.To display the list of names of all the teachers in alphabetical order
Ans. a. Select * from Teachers where subject = "COMPUTER";
b.Select * from teachers where Salary >= 20000 and Salary <= 35000;
C- Select Subject from Teachers where Age > 40;
d.Select * from Teachers order by Name; OR .Select Name from Teachers order
by Name;

You might also like