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

Term 2 Practical File SQL

Done

Uploaded by

Sumit Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Term 2 Practical File SQL

Done

Uploaded by

Sumit Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

PROGRAM 1

Write a SQL query to create a database.

Query:

CREATE DATABASE Practical;

PROGRAM 2

Write a SQL query to create a Student table with the student id, Rno, class section,
gender, name, dob and marks as attributes where the student Id is the primary key.

Query:

CREATE TABLE Student(StudentID int primary key ,Rno int,Class int ,Section char ,Gender
char,Name varchar(20),DOB date, Marks float);

SELECT * FROM Student;

Output:

PROGRAM 3

Write a SQL query to insert the details of at least 10 students in the above table.

Query:

INSERT INTO Student VALUES(16171,1, 11, "A", "M", "Shyam", '2004-12-22', 96),
(16172,13, 10, "B", "F", "Priya", '2006-07-04', 50), (16173,15, 12, "D", "M", "Rahul",
'2005-03-14', 62), (16174,10, 11, "A", "M", "Vivkey", '2007-07-24', 99), (16175,21, 10,
"C", "F", "Ranjeet", '2005-11-11', 72),(16176,25, 11, "A", "M", "John", '2006-01-20',
45), (16177,7, 12, "B", "F", "Goerge", '2003-01-04', 73), (16178,20, 11, "C", "M",
"Luffy", '2005-05-10', 63),(16179,17, 11, "A", "M", "Mohan", '2007-05-10', 84),
(16180,26, 10, "D", "F", "Arlo", '2007-05-10', 69);

SELECT * FROM Student;


Output:

PROGRAM 4

Write a SQL query to delete detail of particular student in the above table.

Query:

DELETE FROM Student WHERE StudentID = 16171;

SELECT* FROM Student;

Output:

PROGRAM 5

Write a SQL Query to increase marks by 5% for those students who have Rno more than
20.

Query:

Update Student Set Marks = Marks+5 Where Rno>20;


Output:

PROGRAM 6

Write a SQL Query to display the entire content of the student table.

Query:

SELECT * FROM Student;

Output:

PROGRAM 7

Write a SQL Query to display Rno, Name and Marks of those students who are
scoring marks more than 50.

Query:

Select Rno, Name , Marks from Student Where Marks > 50;

Output:
PROGRAM 8

Write a SQL Query to find the average of marks from the student table.

Query:

Select Avg(Marks) From Student;

Output:

PROGRAM 9

Write a SQL Query to find the number of students, who are from section ‘A’.

Query:

Select Count(*) From Student Where Section = 'A';

Output:

PROGRAM 10

Write a SQL Query to add a new column email in the above table with appropriate
data type.

Query:

Alter Table Student Add column emailID char(20); Select* from Student;

Output:
PROGRAM 11

Write a SQL Query to add the email ids of each student in the previously created
email column.

Query:

Update Student Set emailID = '[email protected]' Where StudentID = 16172;

Update Student Set emailID = '[email protected]' Where StudentID = 16173;

Update Student Set emailID = '[email protected]' Where StudentID = 16174;

Update Student Set emailID = '[email protected]' Where StudentID = 16175;

Update Student Set emailID = '[email protected]' Where StudentID = 16176;

Update Student Set emailID = '[email protected]' Where StudentID = 16177;

Update Student Set emailID = '[email protected]' Where StudentID = 16178;

Update Student Set emailID = '[email protected]' Where StudentID = 16179;

Update Student Set emailID = '[email protected]' Where StudentID = 16180;

Select*From Student;

Output:
PROGRAM 12

To display the information of all the students, whose name starts with ‘An’.

Query:

Select * From Student Where Name like 'An%';

Output:

PROGRAM 13

Write a SQL to display Rno, Name , DOB of those students who were between ‘2005-01-
01’ and ‘2005-12-31’.

Query:

Select Rno, Name, DOB from Student Where DOB Between '2005-01-01' and '2005-
12-31';

Output:

PROGRAM 14

Write a query to display Rno, Name , DOB, Marks, email of those male students in
ascending order of their names.

Query:

Select Rno, Name, DOB, Marks, emailID from Student where Gender = 'm' order by
Name asc;
Output:

PROGRAM 15

Write a SQL query to display Rno, Gender, Name, DOB, Marks, email in desc order of their
mark.

Query:

Select Rno, Gender, Name, DOB, Marks, emailID from Student order by Marks desc;

Output:

PROGRAM 16

Write a SQL Query to display unique section available in the table.

Query:

Select Distinct section From Student;

Output:
PROGRAM 17

Write a SQL Query to show min, max and sum of the marks of student table.

Query:

1) Select MIN(Marks) From Student;

Output:

2) Select Max(Marks) From Student;

Output:

3) Select Sum(Marks) from Student;

Output:

PROGRAM 18

Create a table named WORKER with column Ecode,Name, Desig, PLevel, DOJ and
DOB.

Query:

CREATE TABLE WORKER (ECODE INT PRIMARY KEY, NAME CHAR(25),DESIG CHAR(30),

PLEVEL CHAR (5) NOT NULL, DOJ DATE, DOB DATE);

Select * from WORKER;

Output:
PROGRAM 19

Write a SQL query to insert any five records in table worker of your choice.

Query:

INSERT INTO WORKER VALUES

(11, 'RADHE', 'SUPERVISOR', 'P001', '2004-07-13', '1981-08-23'),

(12, 'CHANDER', 'OPERATOR', 'P003', '2010-02-22', '1987-12-07'),

(13, 'FIZZA', 'OPERATOR', 'P003', '2009-06-14', '1983-09-14'),

(15, 'AMEEN', 'MECHANIC', 'P002', '2006-08-21', '1984-03-13'),

(18, 'SANYA', 'CLERK', 'P002', '2005-12-19', '1983-06-09');

SELECT* FROM WORKER;

Output:

PROGRAM 20

Write SQL commands for the following statements

(i) To display the details of all Workers in descending order


(ii) To display NAME and DESIG of those workers whose PLEVEL is either P001 or
P002
(iii) To display the content of all the workers table, whose DOB is in between ’19-JAN-
1984’ and ’18-JAN-1987’.
(iv) To add a new row with the following:
19,’DAYA’, ‘ Operator’, ‘P004’, ’18-JUN-2008’, ’11-JUL-1984’.
Queries:

(i) SELECT * FROM WORKER ORDER BY DOB DESC;

Output:

(ii) SELECT NAME,DESIG FROM WORKER WHERE PLEVEL = 'P001'or PLEVEL =


'P002';

Output:

(iii) SELECT * FROM WORKER WHERE DOB BETWEEN ’19-JAN-1984’ AND ’18-JAN-
1987’;

Output:

(iv) INSERT INTO WORKER VALUES(19, 'DAYA', 'OPERATOR', 'P004', '2008-06-18' ,


'1984-07-11');

Output:
S.No PROGRAMS Signature
1. Write a SQL query to create a database.

2. Write a SQL query to create a Student table with the student id, Rno,
class section, gender, name, dob and marks as attributes where the
student Id is the primary key.
3. Write a SQL query to insert the details of at least 10 students in the
above table.
4. Write a SQL query to delete detail of particular student in the above
table.
5. Write a SQL Query to increase marks by 5% for those students who
have Rno more than 20.
6. Write a SQL Query to display the entire content of the student table.

7. Write a SQL Query to display Rno, Name and Marks of those students
who are scoring marks more than 50.
8. Write a SQL Query to find the average of marks from the student table.

9. Write a SQL Query to find the number of students, who are from
section ‘A’.
10. Write a SQL Query to add a new column email in the above table with
appropriate data type.
11. Write a SQL Query to add the email ids of each student in the
previously created email column.
12. To display the information of all the students, whose name starts with
‘An’.
13. Write a SQL to display Rno, Name , DOB of those students who were
between ‘2005-01-01’ and ‘2005-12-31’.
14. Write a query to display Rno, Name , DOB, Marks, email of those male
students in ascending order of their names.
15. Write a SQL query to display Rno, Gender, Name, DOB, Marks, email in
desc order of their mark.
16. Write a SQL Query to display unique section available in the table.

17. Write a SQL Query to show min, max and sum of the marks of student
table.
18. Create a table named WORKER with column Ecode,Name, Desig,
PLevel, DOJ and DOB.
19. Write a SQL query to insert any five records in table worker of your
choice.
20. Write SQL commands for the various statements
GOVT. CO-ED SR. SEC. SCHOOL,
A6 BLOCK, PASCHIM VIHAR, DELHI-110063

INFORMATICS PRACTICES
PRACTICAL FILE

12th – A
SUBMITTED BY:- Ankit Kumar Sharma(09)
SUBMITTED TO:- Manisha Mam(PGT CS)

You might also like