Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
72 views

Database and MySQL Assignment

Uploaded by

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

Database and MySQL Assignment

Uploaded by

atharv sooraj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Database and MySQL assignment

1) command is used to change table structure in SQL.


(A) update (B) change (C) alter (D) modify

2) Which of the following commands will remove the entire database from MYSQL?
(A) DELETE DATABASE (B) DROP DATABASE
(C) REMOVE DATABASE (D) ALTER DATABASE
3) is a non-key attribute, whose values are derived from the primary key of some other
table.
(A) Primary Key (B) Candidate Key (C) Foreign Key (D) Alternate Key

4) The SELECT statement when combined with clause, returns records


without repetition.
(A) DISTINCT (B) DESCRIBE (C) UNIQUE (D) NULL

5) Which of the following is not part of a DDL query?


a) DROP b)MODIFY c)DISTINCT d)ADD

6) command is used to remove a column from a table in SQL.


(a) update (b)remove (c) alter (d)drop

7) Which of the following commands will delete the rows of table?


(a) DELETE command (b) DROP Command
(c) REMOVE Command (d) ALTER Command
8) Which of the following ignores the NULL values inSQL?
a)Count(*) b) count() c)total(*) d)None of these
9) If a table which has one Primary key and two alternate keys. How many Candidate keys
will this table have?
(A) 1 (B) 2 (C)3 (D) 4
10) Which SQL command can change the degree of an existing relation?
11) What will be the output of the query?
SELECT * FROM products WHERE product_name LIKE 'App%';
(A) Details of all products whose names start with 'App'
(B) Details of all products whose names end with 'App'
(C) Names of all products whose names start with 'App'
(D) Names of all products whose names end with 'App'
12) In which datatype the value stored is padded with spaces to fit the specified length.
(A) DATE (B) VARCHAR (C)FLOAT (D)CHAR
13) Which aggregate function can be used to find the cardinality of a table?
(A)sum() (B) count() (C)avg() (D)max()

14) Assertion (A): A SELECT command in SQL can have both WHERE and HAVING clauses.
Reasoning (R): WHERE and HAVING clauses are used to check conditions, therefore,
these can be used interchangeably.

2mark :
15) A) What constraint should be applied on a table column so that duplicate values are
not allowed in that column, but NULL is allowed.
B) What constraint should be applied on a table column so that NULL is not allowed
in that column, but duplicate values are allowed.
16) A)Write an SQL command to remove the Primary Key constraint from a table,
named MOBILE. M_ID is the primary key of the table.
B) Write an SQL command to make the column M_ID the Primary Key of an
already existing table, named MOBILE.
17) Differentiate between DDL and DML with one Example each.
18) Write two points of difference between ALTER and UPDATE command in SQL.
19) What do you understand by the terms PRIMARY KEY and UNIQUE KEY of a
relation in relational database
20) Categorize the following commands as DDL or DML: DROP, DELETE, SELECT,
ALTER
21) Differentiate between count(column_name) and count(*) functions in SQL with
appropriate example.
22) What is the difference between WHERE and HAVING clause of SQL statement?

TABLES and QUERIES :


23) Consider the table ORDERS as given below

O_Id C_Name Product Quantity Price

1001 Jitendra Laptop 1 12000


1002 Mustafa Smartphone 2 10000
1003 Dhwani Headphone 1 1500

Note: The table contains many more records than shown here.

A) Write the following queries:


(I)To display the total Quantity for each Product, excluding Products with total
Quantity less than 5.
(II) To display the orders table sorted by total price in descending order.
(III) To display the distinct customer names from the Orders table.
(IV) Display the sum of Price of all the orders for which the quantity is null.
B) Write the output
(I) Select c_name, sum(quantity) as total_quantity from
orders group by c_name;
(II) Select * from orders where product like '%phone
%';
(III) Select o_id, c_name, product, quantity, price from
orders where price between 1500 and 12000;
(IV) Select max(price) from orders;

24) Saman has been entrusted with the management of Law University Database. He needs
to access some information from FACULTY and COURSES tables for a survey
analysis. Help him extract the following information by writing the desired SQL queries
as mentioned below.

Table: FACULTY

Table: F_ID FName LName Hire_Date Salary


102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
COURSES
C_ID F_ID CName Fees
C21 102 Grid Computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000
(I) To display complete details (from both the tables) of those Faculties whose salary is
less than 12000.
(II) To display the details of courses whose fees is in the range of 20000 to 50000 (both
values included).
(III) To increase the fees of all courses by 500 which have "Computer" in their Course
names.
(IV) (A) To display names (FName and LName) of faculty taking System Design.
OR
(B) To display the Cartesian Product of these two tables.
Write the output

i) SELECT C.CName, C.Fees, F.FName, F.LName FROM


COURSES C NATURAL JOIN FACULTY F;

ii) SELECT C.CName, F.FName, F.LName FROM COURSES C, FACULTY F


WHERE C.F_ID = F.F_ID AND F.Hire_Date > '2000-01-01';

iii) SELECT C.CName, C.Fees, F.FName, F.LName FROM COURSES C,


FACULTY F WHERE C.F_ID = F.F_ID AND C.Fees > 15000;
iv) SELECT AVG(Salary) AS Average_Salary FROM FACULTY;

25)Write the output of the queries (i) to (vi) based on the table given below:
TABLE: CHIPS

BRAND_NAME FLAVOUR PRICE QUNATITY

LAYS ONION 10 5
LAYS TOMATO 20 12
UNCLE CHIPS SPICY 12 10
UNCLE CHIPS PUDINA 10 12
HALDIRAM SALTY 10 20
HALDIRAM TOMATO 25 30
(i) Select BRAND_NAME, FLAVOUR from CHIPS where PRICE <> 10;
(ii) Select * from CHIPS where FLAVOUR=”TOMATO” and PRICE > 20;
(iii) Select BRAND_NAME from CHIPS where price > 15 and QUANTITY < 15;
(iv) Select count( distinct (BRAND_NAME)) from CHIPS;
(v) Select price , price *1.5 from CHIPS where FLAVOUR = “PUDINA”;
(vi) Select distinct (BRAND_NAME) from CHIPS order by BRAND_NAME desc;
26) Consider the following tables Emp and Dept:
Relation: Emp

empcode ename deptid Salary deptid dname


1001 TOM 10 10000 10 Physics
1002 BOB 11 8000
11 Chemistry
1003 SID 10 9000
12 Biology
1004 JAY 12 9000

What will be the output of the following


statement?
SELECT * FROM Emp NATURAL JOIN Dept WHERE dname='Physics';

23) Write output of the queries (i) to (iv) based on the table Sportsclub
Table Name: Sportsclub
playerid pname sports country rating salary

10001 PELE SOCCER BRAZIL A 50000

10002 FEDERER TENNIS SWEDEN A 20000

10003 VIRAT CRICKET INDIA A 15000

10004 SANIA TENNIS INDIA B 5000

10005 NEERAJ ATHLETICS INDIA A 12000

10006 BOLT ATHLETICS JAMAICA A 8000

10007 PAUL SNOOKER USA B 10000


(i) SELECT DISTINCT sports FROM Sportsclub;
(ii) SELECT sports, MAX(salary) FROM Sportsclub GROUP BY sports
HAVING sports<>'SNOOKER';
(iii) SELECT pname, sports, salary FROM Sportsclub WHERE
country='INDIA' ORDER BY salary DESC;
(iv) SELECT SUM(salary) FROM Sportsclub WHERE rating='B';
24)Based on the given set of tables write answers to the following questions.
Table: flights
flightid model company
10 747 Boeing
12 320 Airbus
15 767 Boeing
Table: Booking
ticketno passenger source destination quantity price Flightid
10001 ARUN BAN DEL 2 7000 10
10002 ORAM BAN KOL 3 7500 12
10003 SUMITA DEL MUM 1 6000 15
10004 ALI MUM KOL 2 5600 12
10005 GAGAN MUM DEL 4 5000 10
a) Write a query to display the passenger, source, model and price for all
bookings whose destination is KOL.
b) Identify the column acting as foreign key and the table name where it
is present in the given example.

25)Tarun created the following table in MySQL to maintain stock for the
items he has.
Table : Inventory
Productid pname company stock price ratin
g
10001 Biscuit Parley 1000 15 C
10002 Toffee Parley 500 5 B
10003 Eclairs Cadbury 800 10 A
10004 Cold Drink Coca Cola 500 25 NULL
10005 Biscuit Britania 500 30 NULL
10006 Chocolate Cadbury 700 50 C
Based on the above table answer the following questions.
a) Identify the primary key in the table with valid justification.
b) What is the degree and cardinality of the given table.
c) Write a query to increase the stock for all products by 20 whose
company is Parley.
d) Write a query to delete all the rows from the table which are not
having any rating.
26)Write the output of the queries (a) to (d) based on the table
(a) SELECT min(Population) FROM country;
(b) SELECT max(SurfaceArea) FROM country Where Lifeexpectancy <50;
(c) SELECT avg(LifeExpectancy) FROM country Where CName Like "%G%";
(d) SELECT Count(Distinct Continent) FROM country;
OR
(a) Identify the candidate key(s) from the table Country.
(b) Consider the table CAPITAL given below:

Which field will be considered as the foreign key if the tables


COUNTRY and CAPITAL are related in a database?

27) Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher
and Posting given below:
Table: Stationary
S_ID StationaryName Company Price
DP01 Dot Pen ABC 10
PL02 Pencil XYZ 6
ER05 Eraser XYZ 7
PL01 Pencil CAM 5
GP02 Gel Pen ABC 15

Table: Consumer
C_ID ConsumerName Address S_ID
1 Good Learner Delhi PL01
6 Write Well Mumbai GP02
12 Topper Delhi DP01
15 Write & Draw Delhi PL02
1. SELECT count(DISTINCT Address) FROM Consumer;
2. SELECT Company, MAX(Price), MIN(Price), COUNT(*)
from Stationary GROUP BY Company;
3. SELECT Consumer.ConsumerName,
Stationary.StationaryName, Stationary.Price FROM
Stationary, Consumer WHERE Consumer.S_ID =
Stationary.S_ID;

28) Write a output for SQL queries (i) to (iii), which are based on
the table: SCHOOL and ADMIN given below:

i) SELECT SUM (PERIODS), SUBJECT FROM SCHOOL GROUP BY SUBJECT;


ii) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE
DESIGNATION = ‘COORDINATOR’ AND SCHOOL.CODE=ADMIN.CODE;
iii) SELECT COUNT (DISTINCT SUBJECT) FROM SCHOOL;

You might also like