Mysql Assignment Cs - Class 12 Second Term Exerecise 1: Table: Member

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

MySQL Assignment

CS - Class 12th Second Term

Exerecise 1: Table : Member

TN TNAME SALARY AREA AGE GRAD DEPT


O E
1 Shalini 40000 WEST 45 C CIVIL
2 Akriti 35000 SOUT 38 A ELEC
H
3 Shyam 60000 NORT 52 B CIVIL
Prasad H
4 Brij Mohan 38000 NORT 29 B CIVIL
H
5 Varun 42000 EAST 35 A COMP
6 Chanchal 29000 SOUT 34 A MECH
H

1. Create the table Member with Primary key constraint to TNO and NOT NULL constraint to
TNAME, SALARY, AREA, AGE, GRADE, and DEPT. Decide your own suitable data types.
2. Show the structure of the table.
3. Insert records in a table Member.
Insert into member values( , , , , , , , , )

4. Display all the records from table Member.


5. Display TNO and TNAME of all employees from table Member.
6. Drop the constraint NOT NULL of DEPT.

Alter table member drop constraint not null (dept);


7. Add one more column as Address with 20 characters after TNAME.
Alter table member add address char (20) before salary;

8. Add one more column SNO as integer data type as first field.
9. Add one more column BONUS as integer data type at the end.
10. Modify the data type of TNAME as VARCHAR(30).
Alter table member modify Tname varchar(30)
11. Drop the primary key constraint.
12. Add a primary key constraint to TNAME.
ALTER TABLE Members
ADD PRIMARY KEY (TNAME);

13. Drop the table.


Drop member;
Alter table member drop area; (in case you want to drop a column

Exercise - 2 Table : Empl

EMPNO ENAME JOB MGR HIREDATE SAL phno COMM DEPT


NO
8369 SheshNag CLERK 8902 1990-12-18 28000 NULL 20
8499 Anya SALESMA 8698 1991-02-20 36000 500 30
N
8521 Shankar SALESMA 8698 1991-02-22 30000 300 30
N
8566 Mustafa MANAGER 8839 1991-04-02 55000 NULL 10
8654 Ritu ANALYST 8698 1992-12-09 70000 NULL 20
8698 Shefani PRESIDEN NUL 1991-11-18 25000 NULL 10
T L 0
1
8882 Radhe Shyam SALESMA 8698 1991-05-01 32000 1200 30
N

1. Create the table Empl with Primary key constraint to EMPNO and NOT NULL constraint to
ENAME, JOB, HIREDATE, SAL and DEPTNO.
2. Insert records in a table Empl.
3. Display all the records from table Empl.
4. Display EMPNO and ENAME of all employees from table Empl.
5. Display ENAME, SAL and SAL added with COMM from table Empl.
6. Write a query to display employee name, salary and department number who are not getting
commission from table Empl.

Select ename,sal,deptno from empl where comm is null;


7. Write a query to display employee number, name, sal and sal * 12 as Annual Salary from table
Empl.
8. List all records whose salary is less than 10000 from table Empl.
9. List all records whose salary is between 20000 and 50000 from table Empl.
10. List the details of all employees who have four letters name.
select * from Empl where ENAME like'____';

11. List the details of all employees whose name starts with ‘M’.
Select * from employees where name like ”m%”;
12. List the details of all employees whose name ends with ‘A’.
Select * from empl where ename like “%a”;
Like “_a%” “ %a%
13. List name of all employees whose commission is not null.
Select ename from empl where comm is not null;
14. List the details of all employees who are either CLERK or SALESMAN.
15. List all records in ascending order of department number.

16. List all records in descending order of salary


17. Increase the salary of all employees by 1000. (permanent/temp)
Select sal+1000 from empl;
Update empl set sal=sal+1000;

18. Delete all records where commission is null.


19. Drop the table.
Table : Club
COACH_ID COACHNAME AG SPORTS DATOFJOIN PAY SE
E X
C Neelkanth Singh 35 Badminton 1996-03-27 10000 M
0
1
C Shivani Pratap 34 Kar 1998-01-20 12000 F
0 ate
2
C Karan Kumar 34 Squash 1998-02-19 12000 M
0
3
C Vasundhra 33 BASKETBALL 1998-01-01 15000 F
0
4
C Zubi 36 SWIMMING 1990-01-12 7500 M
0 n
5
C Shailasha 36 SWIMMING 1998-02-24 6000 F
0
6
C Anki 39 SQUASH 1998-02-24 22000 F
0 ta
7
C Zare 37 KARATE 1998-02-28 11000 F
0 en
8
2
C Sushma 41 SWIMMING 1998-01-13 9000 F
0
9

1. To show all the information about female coaches.


2. To display a report, showing coach name, pay, age and bonus (15% of pay) for all the coaches.
3. To display all the information of coaches who are getting salary in the range of 10000 to 20000.
4. To display all the information of coaches who are less than 35 years of age.
5. To display all the information of KARATE and BASKETBALL coaches.
6. To display all the information about male coaches having age above 35
7. To display all the information of coaches having C05 or C07 as coach_id.
8. To display all the information of coaches who were hired in year 1998.
9. To display distinct sports.
10. To display information of all the coaches whose name starts with S.
11. To display information of all the coaches whose name ends with A.
12. To display information of all the coaches who have five-letter names.
13. To list the names of all coaches with their date of joining (DATOFJOIN) in descending order.
14. To list all the information about coaches in ascending order of age.
15. To list all the information about coaches in descending order of age and ascending order of pay.
16. To list all the information about coaches in ascending order of name
17. To increase the pay of all the coaches by 1000.
18. To decrease the pay of all the male coaches by 500.
19. To change the age to 40 of coaches whose coach_id is C04.
20. To change the age to 47 and sports to SWIMMING of coaches whose coach_id is C08.
21. To delete all the records of male coaches who are below 35 years of age.
22. To delete all the records of female coaches.
23. To delete all records.
24. To delete the table.

Exercise : 3 PRACTICE QUESTIONS


1. What are the candidate keys in the following table GARMENT?

GCODE DESCRIPTION PRICE FCOD READYDATE


E
10023 FORMAL SHIRT 1150 F03 2008-12-19
10001 INFORMAL SHIRT 1250 F01 2008-01-12
10024 BABY TOP 750 F02 2008-06-06
0019 FROCK 750 F03 2008-06-06

2. Differentiate between DROP and DELETE command.


3.Shivam wants to make changes in his name. Which command should he use.
4. Which command is used to make changes in a field name.
5. Suhani forgot to add Primary Key constraint in her Table .Which command should she use.
6. What is NULL?
7. Which operator can be used in place of BETWEEN?
8. Which operator is used to connect relational expressions in the WHERE clause?
9. Which operator selects values that match any value in the given
list
of values?
10 . What is the difference between _ and % symbol?

Exercise : 4 – 1. Define and Identify the Primary key and Candidate key(s) in the following table
Dept.
Deptno DeptName Location
1 Physics First Floor
0
1
0 English Second
2 Floor
3
1 Chemistry Second
0 Floor
3
1 Computer Third Floor
0
4
1 Maths Third Floor
0
5
2. Vibha has created a table Sales in MySQL.

Salesman_ Com
No m
1001 200
1002 800
1003 NUL
L
1004 800
1005 NUL
L

She has written the following statements:


SELECT Comm FROM Sales WHERE Comm = NULL;
But she gets an error on executing the above statements. Write the correct
statements after removing the errors.

3. A table “Student” has 10 rows and each row has 6 columns. What is the degree and
cardinality of the table?
4. The column Ename of the table “Employee” is given below:

Arpit
Zarina
Kareem
Aruna
Ankit
What will be the output of the following queries:
i. SELECT Ename FROM Employee WHERE Ename like “%a”;
ii. SELECT Ename FROM Employee WHERE Ename like “_r%”;

You might also like