· Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b)...

32
Simple Queries Worksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting 2 rows. What will be the degree and cardinality of this table. (c) Consider the table KID shown below Table : KID Item Code Item DatePurch ase UnitPric e Discount 101 Cot 2017-01- 23 6000 25 102 Frock 2016-09- 23 800 10 103 Soft Toy 2017-06- 17 900 10 104 Baby Socks 2015-10- 16 200 7 105 Baby Suit 2016-09- 20 600 5 Write the query for command (i) to (viii) and output for (ix) to (x). (i) Write command to display item details whose name start from ‘B’. (ii) Write command to arrange the record in descending order on the basis of Unit Price. (iii) Write command to display the item name whose price is maximum.

Transcript of  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b)...

Page 1:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

Simple Queries

Worksheet-1

Q1. (a) Is MySQL case sensitive ? Explain with example.

(b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting 2 rows. What will be the degree and cardinality of this table.

(c) Consider the table KID shown below

Table : KID

Item Code Item DatePurchase UnitPrice Discount101 Cot 2017-01-23 6000 25102 Frock 2016-09-23 800 10103 Soft Toy 2017-06-17 900 10104 Baby Socks 2015-10-16 200 7105 Baby Suit 2016-09-20 600 5Write the query for command (i) to (viii) and output for (ix) to (x).

(i) Write command to display item details whose name start from ‘B’.

(ii) Write command to arrange the record in descending order on the basis of Unit Price.

(iii) Write command to display the item name whose price is maximum.

(iv) Display the details of items whose price between ranges 600 to 800.

(v) To display the list of items whose discount is more than 10%.

(vi) To display name of item and their date of purchase that were purchased after 31st Dec 2016.

(vii) To increase the unit price of each item by 10% of their unit price.

(viii) To display the details of those item whose unit price is more than 5000.

(ix) Select MID (Item, 1,2,) from Kid;

(x) Select AVG(UnitPrice) from Kid where DatePurchase> ‘2016-01-01’;

Page 2:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

Worksheet-2

Q5. (a)Anil has created the following table with name ‘Employee’.ColumnName ConstraintEmpID Primary KeyDOJEname Not NullBasicOne of the rows inserted is as follows :EmpID DOJ Ename BasicA1 2016-02-12 Pradeep 20000

What are the data type of columns EmpiD and DOJ?EmpID DOJ Ename BasicA2 2016-08-09 NULL Rajesh Mishra

Will he be able to successfully insert it ? Give reason.(b) Write the output of following SQL quries:(i) Select Dayofyear(‘2016-01-30’);(ii) Select Mid(‘Welcome to Kanpur’, 2,4);(iii) Select Round (56.484,2);(iv) Select Instr(‘How Computer Work’, ‘mp’);

(c)Consider the following table GYM with details about fitness products being sold in the store. Write command of SQL for (i) to (viii) and output for (ix) to (x).

Table: GYMPCODE

PNAME PRICE MANUFACTURER

P101 Treadmill 21000 Coscore

P102 Bike 20000 Aone

P103 Cross Trainer 14000 Reliable

P104 Multi Gym 34000 Coscore

P105 Massage chair 5500 Regrosene

P106 Belly Vibrator Belt 6500 Ambaway

(i) To display the details of all the producut.(ii)To display the names of all products whose first character is ,'M'(iii) To display the name of all manufacturer without duplicate.(iv) Toupdate price of all product by Rs 200.(v) To add a new column named "Discount" in this table.(vi) To arrange the record on the column Price in descending order.

Page 3:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

(vii) to display the structure of this table.(viii) To add a new record with your own data.(ix)SELECT * FROM GYM WHERE MANUFACTURER NAME

LIKE“%m%”;(x)SELECT COUNT (DISTINCT (MANUFACTURER)) FROM GYM

Worksheet-3

Q1. (a) Distinguish between Single Row and Aggregate function of MySQL. Write one example of each.

(b) Consider the table Teacher given below. Write commands in SQL for (i) to (viii) and output for (ix) to (x)

TEACHERId Name Department Hiredate Category Gender Salary1 John SocialStudies 1994-03-17 TGT F 250002 Anil Art 1990-02-12 PRT M 200003 Bhavika English 1980-05-16 PGT F 300004 James English 1989-10-16 TGT M 250005 Jaspreet Hindi 1990-08-01 PRT F 220006 Disha Math 1980-03-17 PRT F 210007 Siddarth Science 1994-09-02 TGT M 270008 Sonali Math 1980-11-17 TGT F 24500(i)To display the structure of table.(ii) To add a new column games of varchar data type.(iii) To drop the column games we have added.(iv) To display all information about teachers of TGT category.(v) To list the names of female teachers of “English” department.

(vi) To list names, departments and date of hiring of all the teachers in ascending order of

date of joining

(vii) To count the number of teachers in English department.

(viii) SELECT DISTINCT(category) FROM teacher;

(ix) SELECT COUNT(*) FROM TEACHER WHERE Category = "PGT";

(x) SELECT AVG(Salary) FROM TEACHER group by Gender;

Page 4:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

(c) A Table Doctor contain 3 rows and 5 columns in it. Write the degree and cardinality of this table.

Worksheet-4

Q1. (a) Write the difference between DROP TABLE and DELETE command of MySQL.

(b) Name a function of MySQL used to give the first occurrence of a string2 in string1.

(c) Consider the table RESULT given below. Write commands in MySql for (i) to (iv) and output for (v) to (vii)Table :RESULTSHEET

No Name Stipend Subject Average Division1 Konditi 400 English 38 THIRD2 Binny 680 Mathematics 72 FIRST3 Kapil 500 Accounts 67 FIRST4 Vijay 200 Informatics 55 SECOND5 Anandha 400 History 85 FIRST6 Upasna 550 Geography 45 THIRD

(i) To display details of those student who have got Division First and Average

is greater than 70.

(ii) To display details of all students also arrange the record in ascending order

of stipend received.

(iii) To display No and Name of all student while displaying display

“Admission Number” in place of column “No”

(iv) To list the names of those students, who have obtained Division as THIRD

in ascending order of NAME.

(v) To display a report listing NAME,SUBJECT and Annual stipend received

assuming that the stipend column has monthly stipend.

(vi) To count the number of students, who have either Accounts or Informatics

as subject.

(vii) To insert a new row in the table EXAM :

Page 5:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

7, “Rama”, 600, “English”, 74, “Second”

(viii) SELECT MAX(Stipend) FROM RESULTSHEET WHERE DIVISION =

“THIRD”;

(ix) SELECT COUNT(DISTINCT Subject) FROM RESULTSHEET;

(x) SELECT MIN(Average) FROM RESULTSHEET WHERE Subject=

“Accounts”;

Worksheet-5

Q1. (a) A table has 5 column while entering data, value of column number 3 is not available. Anil entered following command. What’s wrong in it? Write correct query after removing error.

INSERT INTO EMPLOYEE

VALUES (101, ‘Ved Prakash’, ‘Accounts’, 30000);

(b) What is the purpose of the following SQL query :

SELECT MAX(SALARY) FROM EMP;

(C) Consider the table Supplier given below. Write command in MySql for (i) to (vii) and output for (viii) to (x) .

Table : Supplier

Scode Pname Supname Qty City Price101 Cold Coffee Nestle 20 Bhopal 55.00102 Parle Biscuit Hide & Seek 10 Delhi 10.00103 Trim Jam Kissan 11 Bhopal 25.00104 Salt Maggi Nestle 15 Mumbai 10.00105 Chocolate Cadbury 17 Delhi 25.00106 Soya Sauce Maggi 30 Mumbai 55.00107 Milk Cake Britannia 70 Delhi 10.00

(i) To modify column City and write “New Delhi” in place of “Delhi”.

(ii) To display length (Number of character) of all Product Name.

(iii) Increase the price of all product by Rs. 5 whose current price is 50.

(iv) To drop column Price from table.

Page 6:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

(v) To display names of the products, whose supname starts with ‘B’ in ascending

order of Price ?

(vi) To display Supplier code, Product name and City of the products whose quantity

is less than 15.

(vii) To count distinct City in the table.

(viii) Select Pname from supplier where Pname IN (“Bread”,”SaltMaggi”);

(ix) Select Count(distinct city) from supplier;

(x) Select max(Price) from supplier where City=”Bhopal” ;

WORK SHEET 6

1) Differentiate between TCL and DDL commands.

2) Write the output of the following SQL statements :

(i) Select char(66) as ‘Char’;(ii) Select Concat(substr(“Ram”,2),”jain”) “StudentName”;(iii) Select UPPER(“Rahul Kumar”);(iv) Select RIGHT(“Informatics Practices”,5);

3) Write the SQL commands for the i) to iv) and write the output v to viibasis of table STUDENT.

TABLE: STUDENT

No Name Stipend Stream AvgMark Grade Class

1 Kamlesh 400.00 Medical 78.0 B 12B2 Praveen 450.00 Commerce 88.2 A 11C3 Manoj 300.00 Commerce 67.6 C 12C4 Laxmi 350.00 Humanities 77.1 B 12C

5 Suja 350.0Nonmedical

78.6 B 11A

6 Basima 500.00 Humanities 89.4 A 12B

7 Soju 400.00Nonmedical

88.4 A 11A

8 Deepa 250.00Nonmedical

75.5 B 12A

Page 7:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

9 Shushil 450.00 Humanities 92.4 A 12A10 Baba 300.00 Commerce 92.5 A 12C

(i) Select all the Commerce stream students.(ii) List the names of those students who are in class 12 sorted by Stipend.(iii) List the Name, Grade, Class of students sorted by AvgMark in descending order.(iv) Display the Name, Stipend, Stream and amount of stipend received in a year

assuming that the Stipend is paid every month.

(v) SELECT TRUNCATE(AvgMark,0) FROM Student WHERE AvgMark<85; (vi) SELECT ROUND(AvgMark) FROM Student WHERE Grade=’A’;

(vii) SELECT CONCAT(Name, Stream) FROM Student WHERE Class = ‘11A’; (viii) SELECT LEFT(Stream, 2) FROM Student;

WORKSHEET 7

1) Differentiate between group by and order by clause?

2)Write the output of the following SQL statements

i. SELECT CURDATE() AS ‘TODAY’; iiSELECT DAYOFYEAR(‘2010-02-28’);

iii SELECT POW(2,3);

IV) SELECT DAYOFWEEK(CURDATE());

3 Consider the table GARMENTgiven below, write command in SQL for (a) to (d) and output for (e) to

(h).

Table : GARMENT

GCODE DESCRIPTION PRICE FCODE READYDATE

10023 PENCIL SKIRT 1150 F03 2015-11-19

10001 FORMAL SHIRT 1250 F01 2015-12-22

10012 INFORMALS 1550 F02 2015-12-05

10024 BABY TOP 750 F03 2015-11-30

Page 8:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

10007 FORMAL PANT 1350 F01 2015-11-29

10009 FROCK 850 F04 2015-11-28

a. To display gcodeand description of each garment in descending order of GCODE.

b. To display the details of all the garments, which have READYDATEbetween ‘2015-11-19’ and ‘2015-

11-29’ (both values included).

c. To display average PRICE of all the garments whose FCODE is F03.

d. To display maximum and minimum PRICE from GARMENTS table.

e. select sum(price) from garment where fcode=’F01’;

f. select count(distinct fcode) from garment;

g. select gcode , price from garment where description like ‘%C%’;

h. select FCODE, PRICE from GARMENT where PRICE<1000;

WORKSHEET 8

1) What is the use of USE and DESCRIBE Command in My Sql?

2) Write the output of the following SQL statements

ii. SELECT ROUND(1023.432,1); iii. SELECT UPPER(‘master’); iv. SELECT LENGTH(‘ABS Public School’); v. SELECT SUBSTR(TRIM(‘ABS Public School’,1,3);

3) Consider the table given below, write command in MySQL for (i) to (iv) and output for (v) to (viii). Table :STUDENT

Page 9:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

i. To display the name and stream of all students who are in class 12. ii. To display the different Streams available for students. iii. To display name, avgmarks and grade in descending order of grade. iv. To display names of those students whose grade and section are same.v. SELECT STIPEND+500 FROM STUDENT WHERE STREAM LIKE ‘%a%’;

vi. SELECT COUNT(*) FROM STUDENT WHERE GRADE= ‘C’ AND STIPEND>=800; vii. SELECT CLASSSEC FROM STUDENT WHERE AVGMARKS>68 && STREAM= ‘Medical’;

viii. SELECT MAX(STIPEND) FROM STUDENT ;

WORK SHEET 9

1) How is Cross-Join different from Equi-Join?

2) Write output of the following MySQL queries :i) SELECT DAYOFMONTH(NOW());ii) SELECT ROUND(140.295,-2);iii) SELECT INSTR(‘Corporation’, ‘or’);iv) SELECT CONCAT(‘India’, NULL, ‘Australia’);

3 Consider the table EXAM given below. Write command in MySQL for (i) to (vi) and output (v) to (viii).

No Name Stipend Subject Average Division

1 Karan 400 English 68 First

2 Aman 680 Maths 72 First

3 Javed 500 Accounts 67 First

4 Bishakh 200 Informatics 55 Second

5 Sugandha 400 History 35 Third

6

Suparna 550 Geography 45 Third

Page 10:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

(i) To list the names of those students who have obtained Division First in the ascending order of Name.

(ii) To display a report listing Name, Subject and Annual stipend received assuming that the stipend column has monthly stipend.

(iii) To count the number of students, who have either Accounts or informatics as subject.(iv) Insert a new row. 7,”Mohan”,500,”English”,73,”Second”(v) Select AVG(Stipend) from Exam where Division=”Third”;(vi) Select count(Distinct Subject) From Exam;(vii) Select Min(Average) from Exam where Subject=”English”;(viii) Select Sum(Average) from Exam where Division=”First”;

WORKSHEET 10

1) Differentiate between DROP TABLE and DELETE commands in Mysql. Explain each with example.

2) Write the output of the following SQL queries.

(i) SELECT INSTR(‘CORPORATE FLOOR’,’OR’);

(ii) SELECT MID(‘Good Morning’,3,4);

(iii) SELECT LEFT('COMPUTER SCIENCE',7);

(iv) SELECT ROUND(366,1,-1);

3 Consider the table TEACHER given below. Write commands in SQL for (i) to (iv) and output for (v) to (viii)

ID Name Department Hiredate Category Gender salary

1 TanyaNanda Social 2004-03-17 TGT F 25000

2 Saurabh Sharma Art 2010-02-12 PRT M 20000

3 Nadita Arora English 2010-05-16 PGT F 30000

4 James Jacob English 2008-10-16 TGT M 25000

Page 11:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

5 Jaspreet Kaur Hindi 2000-08-01 PRT F 22000

6 DishaSehgal Math 2008-03-17 PRT F 21000

7 Siddharth Kapoor Science 200-09-02 TGT M 27000

8 Sonali Mukherjee Math 2011-11-17 TGT F 24500

i. To display all information about teachers of PGT category.ii. To list the names of female teachers of Hindi department.iii. To listnames, departments, and hiring dates of all the teachers in ascending order of hiring dates.iv. To count the number of teachers in English department.v. SELECT MAX(Hiredate) FROM Teacher;vi. SELECT DISTINCT(category) FROM Teacher;vii. SELECT COUNT (*) FROM TeacherWHERE Category = ‘PGT’;viii. SELECT AVG(Salary) FROM Teacher GROUP BY Gender;

Join QueriesWorksheet- 1

6(a) Write an SQL query to create the table “BookDetails“ with the following structure-

Field Type Constraint

Book_Id Varchar(4) Primary Key

Book_Name Varchar(30)

Author_Name char(30) Default “BPB”

Publisher Varchar(20)

Price Integer Check Price >0

Type Varchar(15)

Quantity Integer Not Null

2

(b) In a database there are two tables ‘Patient’ and ‘Doctors’ are shown below-Table: Patient

Name Patient_No Date_Adm Doctor_No

Aneesh P104 2009-05-15 502

Shraddha K P202 2010-01-11 165

Reshmi Nair P754 2007-12-31 325

2

Page 12:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

Sunitha P P612 2010-04-22 165

Table: DoctorDoctor_No Doctor_Name Specialty

122 Dr. Sabir Khan Urology

165 Dr.R. K. Tiwari Neurology

325 Dr. S.L. Sargaiya Surgery

502 Dr. Priya Nephrology

530 Dr. Kamal Kishore Dentist

i) Name the columns which can be made ‘Primary Key’ in both the tables.ii) What will be the cardinality of Cartesian product of both the tables?

c Consider the tables given below.Table : STOCK

Itcode

Itname Dcode

Qty unitpr Stkdate

452 Drawing Sheet 101 80 21 31-June-2017

457 Sharpener Camlin 102 65 13 21-Apr-2017

467 Eraser Natraj 101 40 6 11-Dec-2017

469 Gel Pen Montex 103 56 10 03-Jan-2017

407 Geometry Box 101 30 65 15-Nov-2017

421 Parker Premium 102 60 109 27-Oct-2017

427 Office File 103 20 34 13-Sep-2017

Table : DEALERSDcode Dname Location

101 Vikash Stationers Lanka Kanpur

102 Bharat Drawing Emporium Luxa Lucknow

6

Page 13:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

103 Banaras Books Corporation Bansphatak Varanasi

With reference to these tables, write commands in SQL for (i) and (ii) and output for (iii) below-

(i) To display the amount that has been spent to purchase Office file & Sharpener camlin.

(ii) To display all the items of Vikash Stationers. (iii) SELECT DCODE,COUNT(QTY),AVG(UNITPR) FROM STOCK GROUP BY DCODE;

Worksheet-2

6(a) What is Primary Key and Candidate Key? Discuss with example. 2(b) What is the difference between Drop and Delete Command? Discuss with example. 2( c) Consider the following two tables stored in a database

The "Persons" table:

P_Id LastName FirstName Address City1 Gupta Naresh Railway Colony 14 Bhopal2 Khan Wasim KV No 2 Raipur3 Singh Sanjeev Radha Apartment Bhilai

The "Orders" table:

6

O_Id OrderNo

P_Id

1 77895 32 44678 33 22456 24 24562 1

Page 14:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

Write MySQL queries for the following(i) To display FistName, Address of all the persons with their corresponding OrderNo.(ii) To display FisrtName , City and OrderNO where LastName begins with the letter ‘K’(iii) To change the Address to LIC Colony 34 where the P_Id is equal to 1

Worksheet-3

6(a) Write SQL to Create the following table BANK with specified constraints

Column Name Data type Constraint

BankCode Character of 10 size Primary Key

Branch Character of 30 size

Location Character of 30 size City can have only four values “Hyderabad”, ”Delhi”,”Goa”,”Bhopal”

Budget Numeric(7,2)

2

(b) Can we change the column name using Alter table command? Change the data type of Budget column of above mentioned BANK Table to Numeric(10,2) and add default value to 1000000.

2

( c) Consider the following tables FURNITURE and TYPE. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii) 6 TABLE : FURNITURE

Page 15:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

FID FNAME TYPENO CHARGES ARRIVAL

1 WHITE LOTUS F01 30000 21-11-2012

2 PINK FEATHER F02 7500 16-11-2012

3 DOLPHIN F02 9500 14-11-2012

4 DECENT F01 25000 5-09-2011

5 COMFORT F03 15000 12-10-2011

6 ROYAL F02 6500 3-05-2011

7 ECONO F03 9500 1-06-2012

TABLE : TYPE

TYPENO TYPENAME DISCOUNT

F01 DOUBLE BED 30

F02 BABY COT 20

F03 OFFICE TABLE 10

(i) To display all the details of furniture whose CHARGES is more than 10000(ii) To increase the CHARGES of furniture by 5% of existing charge for furniture

arrived after 1-09-2011(iii) To display the details of furniture of type OFFICE TABLE(iv) To insert a new row with the following data in FURNITURE table

8, “Velvet Touch”, “F01” , 25000, “25-03-2011”(v) Select TYPENO, count(* ) from FURNITURE group by TYPENO;

(vi) Select FNAME, CHARGES from FURNITURE where FNAME like “ %T “;

Page 16:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

Worksheet-4

6(a) Consider the following EMP and DEPT table

Write the SQL command to get the following. (any 6)a. Show the minimum, maximum and average salary of Managers.b. Count the number of Clerk in the Organization.c. Display the Designation wise list of employees with name, Sal and Date of Joining.d. Count the number of employees who are not getting commission.e. Show the average salary for all departments with more than 5 working people.f. List the count of Employees grouped by DeptID.g. Display the maximum salary of employees in each Department.h. Display the name of Employees along with their Designation and Department Name.i. Count the number of Employees working in ACCOUNTS department.

6

Page 17:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

(b) Write Mysql command to create the Table Employee with the given constraints.Table: EMPLOYEE

Column Name

EmpID EmpName EmpAdd EmpPhone EmpSal DeptID

Key type Primary Foreign

Null/Unique

Not null unique

Foreign Key table

name

Department

Foreign key

colomn

DeptId

Data type integer char varchar integer double integer

Length 4 25 30 10 9,2 2

2

(c ) Does MySQL allow to change the primary key in all cases? If there is some specialcase, please mention.

2

Page 18:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

Worksheet-5

6(a) At the time of creation of table X, the data base administrator specified Y as thePrimary key. Later on he realized that instead of Y, the combination of column P andQ should have been the primary key of the table. Based on this scenario, answer the following questions:a. Is it possible to keep Y as well as the combination of P and Q as the primary key?b. What statement(s) should be entered to change the primary key as per therequirement.

2

(b) What is the difference between Drop and Delete Command? 2( c) Consider the following tables SCHOOL and ADMIN. Write SQL commands for the

statements (i) to (iv) and give outputs for SQL queries (v) to (viii).SCHOOL

CODE TEACHERNAME SUBJECT DOJ PERIODS EXPERIENCE1001 SAJI ENGLISH 12/03/2009 24 101009 RUBI PHYSICS 03/09/2008 26 121203 JAYANTHI ENGLISH 09/04/2000 27 51045 AMIT SINHA MATHS 24/08/2000 24 151123 ASHOK RAO PHYSICS 16/07/1999 28 31167 HARI KRISHNAN CHEMISTRY 19/10/2017 27 5

6

Page 19:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

1215 AMIT PANDEY PHYSICS 11/05/2016 22 16ADMIN

CODE GENDER DESIGNATION1001 MALE VICE PRINCIPAL1009 FEMALE COORDINATOR1203 FEMALE COORDINATOR1045 MALE HOD1123 MALE SENIOR TEACHER1167 MALE SENIOR TEACHER1215 MALE HOD

i) To display TEACHERNAME, PERIODS of all teachers whose periods less than 25.ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and ADMIN

whose gender is male.iii) To display thenumber of teachers in each subject.iv) To display CODE, TEACHERNAME and SUBJECT of all teachers who have joined the

school after 01/01/2008.v) SELECT MAX (EXPERIENCE), SUBJECT FROM SCHOOL GROUP BY SUBJECT;vi) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE DESIGNATION =

‘COORDINATOR’ AND SCHOOL.CODE=ADMIN.CODE;vii) SELECT DESIGNATION, COUNT (*) FROM ADMIN GROUP BY DESIGNATION HAVING

COUNT (*) <2;

Worksheet – 6Time : 30 min M.M.10Write answers at the back side of the sheet

1. Write SQL query to create a table ‘Song’ with the following structure : 2

Field Type ConstraintSongid Integer Primary keyTitle Varchar (50) Not NullDuration Integer Check >=3 and <=8ReleaseDate DateLanguage Varchar(20) Default 5

Page 20:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

2. In a database there are two tables ‘BRANDtab’ and ‘ITEM’ as shown below: 1+1

i) What should be the datatype of column PRICE.ii) Write SQL command to Identify foreign key in ITEM table.

3. Write SELECT Statement based on the table BRANDtab and ITEM given In ques 3. 2X3=06I. Write Statement to display ICODE, INAME, BRAND and price from table BRANDtab and

ITEM.II. Write Statement to display ICODE, INAME, BRAND and price from table BRANDtab and

ITEM of items with price more than 50000.III. Write Statement to display ICODE, INAME, BRAND and price from table BRANDtab and

ITEM of items with INAME like “%R”.

Worksheet – 7Time : 30 min M.M.10Write answers at the back side of the sheet

1. Create Table EMPLOYEE as per the structure given below : 2Table : EMPLOYEE :

Column Name Datatype Size Constraintempno integer Primary Keyename char 20 Not Nulljob char 10 Not Nullmgr integerhiredate datesal decimal 10,2 >2000comm integerdeptno integer Foreign Keygender char 1 default ‘M’

Page 21:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

2. Consider the following tables GAMES & PLAYER and Write the answers of the questions that follow : 2Table: GAMES

GCode GameName Number PrizeMoney ScheduleDate101102103105108

Carom BoardBadmintonTable TennisChessLawn Tennis

22424

500012000 8000 900025000

2019-01-232018-12-122020-02-142018-01-012019-03-19

Table: PLAYERPCode Name Gcode

12345678

Nabi AhmadRavi SahaiJatinNazneenViratYuvrajSaniaGeeta

101108103103102101105108

I. Name the Primary keys in both the tables and Foreign Key in PLAYER Table.II. In the table ‘PLAYER’, values in GCODE are repeated in the column “Gcode”. Is there any

discrepancy? Give reason.

3. Consider the following tables GAMES and PLAYER given in question 2 and Write SQL commands for the statements given in Q (1) and (2) and give outputs for SQL query (3). 6

I. To display the content player name, gamename of those player whose game is scheduled in the year 2019.

II. To display sum of PrizeMoney for each of the Number of participation groupings (as shown in column Number 3 table Games).

III. SELECT NAME,GAMENAME FROM GAMES G,PLAYER P WHERE P.GCODE=G.GCODE AND NAME LIKE “%A_”;

Worksheet – 8Time : 30 min M.M.10Write answers at the back side of the sheet.

Page 22:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

1. Consider the structure of table campus given below and write statement to CREATE this table. 2

Table : Campus

2. Consider the tables given below : 2

Table : PartyParty Id Descrip tio n Co st P er P erso n

P101 Birthday 400P102 Wedding 700P103 Farewell 350P104 Engagement 450

Table : ClientClientId ClientName Addre s s Pho ne NoOfGuests PartyId

C101 A.K. Antony A-151, Adarsh Nagar 9910195614 80 P101C102 Fauzia Aria K-5/52, Vikas Vihar 8934664481 500 P102C103 Rashi Khanna D-6, Hakikat Nagar 9811665680 50 P101

C104 S.K. Chandra76-A/2, MG Colony, Adarsh

9465877756 100 P104i. How many rows will be present in the Cartesian join of the above mentioned 2 tables?ii. In the table ‘Client’, the PartyID 101 is present twice in the column “PartyId”. Is there any

discrepancy? Give reason.

3. Write commands in SQL for (i) & (ii) and Output for (iii) : 6

i. To display Client Name, Party Description and NoOfGuests * CostPerPerson as Totalcost for those clients whose total cost is more than 200000.

ii. To display ClientId, C l i e n t Name, PartyId and Description of clients for only those parties that have less than 100 NoOfGuests.

iii. SELECT CLIENTNAME,PHONE,DESCRIPTION FROM PARTY P, CLIENT CWHERE C.PARTYID=P.PARTYID AND CLIENTNAME NOT LIKE “%A”;

Worksheet – 9Time : 30 min M.M.10

Column Name Data Type Size ConstraintCampus_id NUMBER 4 PRIMARY KEYCampus_name VARCHAR 50 Not NullCity VARCHAR 20 Not NullPin NUMBER 7 Not NullPhone NUMBER 10 Not Null

Page 23:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

Write answers at the back side of the sheet.

1. Create Table DEPT as per the structure given below : 2Table : DEPT

Column Name Datatype Size Constraintdeptno integer Primary keydname char 20 Not Nullloc char 20

2. Write commands in SQL for (4) to (8) and Output for (9) and (10) based on the table DEPT and EMPLOYEE given below: 2

Table : EMPEMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO

7369 SMITH CLERK 7902 17-DEC-80 800 207499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 307521 WARD SALESMAN 7698 22-FEB-81 1250 500 307566 JONES MANAGER 7839 02-APR-81 2975 207654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 307698 BLAKE MANAGER 7839 01-MAY-81 2850 307782 CLARK MANAGER 7839 09-JUN-81 2450 107788 SCOTT ANALYST 7566 19-APR-87 3000 207839 KING PRESIDENT 17-NOV-81 5000 107844 TURNER SALESMAN 7698 08-SEP-81 1500 0 307876 ADAMS CLERK 7788 23-MAY-87 1100 207900 JAMES CLERK 7698 03-DEC-81 950 30

i. Name the Primary keys in both the tables and Foreign Key in EMP Table.ii. In the table EMP, the v a l u e s i n DEPTNO f i e l d is repeated. Is there any discrepancy?

Give reason.

3. Write commands in SQL for (4) to (8) and Output for (9) and (10) : 6

i. To display ENAME, JOB, DEPTNO, DNAME and (SAL + COMM) * 12 as AnnualSalary for those clients whose AnnualSalary is more than 150000. 2

ii. To display EMPNO, ENAME, D E P T N O and DNAME for e m p l o y e e s that have “SALESMAN” as Job. 2

Page 24:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting

iii. SELECT ENAME, JOB,DNAME FROM EMP E, DEPT DWHERE E.DEPTNO=D.DEPTNO AND E.JOB LIKE “A%T”; 2

Worksheet – 10Time : 30 min M.M.10Write answers at the back side of the sheet

1. Write SQL query to create a table ‘Participant’ with the following structure : 2Field Type ConstraintParticipantID Integer Primary keyName Varchar(50)ArrivalDate DateDepartureDate DatePhone IntegerEmailID Varchar(30)

2. In a database there are two tables ‘BRANDtab’ and ‘ITEM’ as shown below: 1+1

I. How many rows and how many columns will be there in Cartesian product of these two tables.

II. Which operations are possible on table BRANDtab and ITEM among the following : Selection, Projection, Cartesian Product, Union and Join.

3. Write SELECT Statement based on the table BRANDtab and ITEM given In ques 3. 2X3=06

i. To display ICODE, BRAND and INAME of those items who have 'N' anywhere in their NAME.ii. To display ICODE, BRAND, INAME and PRICE for those items whose PRICE is between

50000 and 80000.iii. SELECT I.ICODE, BRAND, COUNT(I.ICODE FROM ITEM I, BRANDtab B

WHERE I.ICODE = B.ICODE AND COUNT(I.ICODE)>1 GROUP BY I.ICODE;

Page 25:  · Web viewSimple Queries W orksheet-1 Q1. (a) Is MySQL case sensitive ? Explain with example. (b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting