Database and MySQL Assignment
Database and MySQL Assignment
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
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?
Note: The table contains many more records than shown here.
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
25)Write the output of the queries (i) to (vi) based on the table given below:
TABLE: CHIPS
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
23) Write output of the queries (i) to (iv) based on the table Sportsclub
Table Name: Sportsclub
playerid pname sports country rating salary
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:
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: