SQL Assignment1
SQL Assignment1
Activity 1: Create a table STUDENT with under mentioned structure by using SQL
Statement:
StdID Number Primary Key
StdName Character (30) NOT NULL
Sex Character(6) Male or Female
Percentage Number
SClass Number
Sec Character
Stream Character(10) Science or
Commerce
DOB Date Date of Birth
Step 4: As you press enter key after typing above statement, 1 recordwill be stored into
STUDENTtable.
Step5: Similarly like step 3, enter other records of the following table.
StdI StdName Sex Percentag Clas Se Stream DOB
D e s c
1001 AKSHRA AGARWAL FEMAL 70 11 A Science 10/11/199
E 6
1002 ANJANI SHARMA FEMAL 75 11 A Commerc 18/09/199
E e 6
1003 ANSHUL SAXENA MALE 78 11 A Commerc 19/11/199
e 6
1004 AISHWARYA SINGH FEMAL 79 11 A Commerc 1/11/1996
E e
1005 AKRITI SAXENA FEMAL 76 11 A Commerc 20/09/199
E e 6
1006 KHUSHI AGARWAL FEMAL 77 11 A Commerc 14/09/200
E e 3
1007 MAAHI AGARWAL FEMAL 74 11 A Science 21/04/199
E 7
1008 MITALI GUPTA FEMAL 78 12 A Science 26/11/199
E 7
1009 NIKUNJ AGARWAL MALE 58 12 A Science 12/7/1997
1010 PARKHI FEMAL 59 12 A Commerc 20/12/199
E e 7
65
101 PRAKHAR TIWARI MALE 43 12 A Science 22/04/199
1 7
101 RAGHAV GANGWAR MALE 58 12 A Commerc 21/12/199
2 e 7
101 SAHIL SARASWAT MALE 57 12 A Commerc 13/08/199
3 e 7
101 SWATI MISHRA FEMAL 98 11 A Science 13/08/199
4 E 6
101 HARSH AGARWAL MALE 58 11 B Science 28/08/200
5 3
101 HARSHIT KUMAR MALE 98 11 B Science 22/05/200
6 3
101 JAHANVI KAPOOR MALE 65 11 B Science 10/1/1997
7
101 STUTI MISHRA MALE 66 11 C Commerc 10/1/1996
8 e
SURYANSH KUMAR
101 AGARWAL MALE 85 11 C Commerc 22/08/200
9 e 7
102 TANI RASTOGI FEMAL 75 12 C Commerc 15/01/199
0 E e 8
102 TANISHK GUPTA MALE 55 12 C Science 11/4/1998
1
102 TANMAY AGARWAL MALE 57 11 C Commerc 28/06/199
2 e 8
102 YASH SAXENA MALE 79 11 C Science 13/3/1998
3
102 YESH DUBEY MALE 85 12 C Commerc 3/4/1998
4 e
Activity 2: Open school database, then select student table and use following SQL statements.
TYPE THE STATEMENT, PRESS ENTER AND NOTE THE OUTPUT
1 To display all the records form STUDENT table.
SELECT * FROM student ;
2. To display ony name and date of birth from the table
STUDENT. SELECT StdName, DOB FROM
student ;
3. To display all students record where percentage is greater of equal to 80 FROM student
table. SELECT * FROM student WHERE percentage >= 80;
4. To display student name, stream and percentage where percentage of student is more than
80 SELECT StdName, Stream, Percentage WHERE percentage > 80;
5. To display all records of science students whose percentage is more than 75 form student
table. SELECT * FORM student WHERE stream = ‘Science’ AND percentage >
75;
Activity 3: Open school database, then select student table and use following SQL statements.
TYPE THE STATEMENT, PRESS ENTER AND NOTE THE OUTPUT
1. To display the STUDENT table structure.
DESCRIBE Student;
4. Type the statement and press enter key, note the new field that you have added as
TeacherID
SELECT * FROM student;
Activity 4
1. To Drop (Delete) a field form a table. For e.g you want to delete TeacherID field.
2. To subtract 5 form all students percentage and display name and percentage.
3.Using column alise for example we want to display StdName as Student Name and DOB as
Date of Birth then the statement will be.
Activity 5:
1. To change astudent name from SWATIMISHRA to SWATI VERMA whose StdID is
1014 and alsochange percentage 86.
UPDATE Student SET StdName = ‘SWATI VERMA’, percentage = 86
WHERE StdId = 1014;
2. To delete the records form student table where StdId is 1016.
DELETE FROM Student WHERE StdID = 1016;
3. Type the following SQL statement and note the output.
SELECT * FROM Student WHERE StdName LIKE 'G_' ;
SELECT * FROM Student WHERE StdName='G';
SELECT * FROM Student WHERE StdName LIKE 'G%' ;
SELECT * WHERE Student WHERE StdName='%G%' ;
4. Display all the streams in student table.
SELECT DISTINCT Stream FROM Student;
5. Note the output of the following statement.
SELECT StdName, Sex, Stream FROM Student WHERE percentage BETWEEN 70 AND
80;
67
Do yourself:
Create a Table Empl to store employee details as shown below and write statements
for following queries based on the table.
1. Consider the Empl table and write SQL command to get the following.
a. Write a query to display EName and Sal of employees whose salary are
greater than or equal to 2200?
b. Write a query to display details of employs who are not getting commission?
c. Write a query to display employee name and salary of those employees who
don’t have their salary in range of 2500 to 4000?
d. Write a query to display the name, job title and salary of employees who don’t
have manager?
e. Write a query to display the name of employee whose name contains “A” as third
alphabet?
f. Write a query to display the name of employee whose name contains “T” as last
alphabet?
g. Write a query to display the name of employee whose name contains ”M”
as First and “L” as third alphabet?
h. Write a query to display details of employs with the text “Not given”, if commission
is null?