0% found this document useful (0 votes)
125 views

MySQL-1

Uploaded by

LAKSHAY Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

MySQL-1

Uploaded by

LAKSHAY Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MySQL-1

If a table has 1 primary key and 3 candidate key, how many alternate keys
will be in the table.
i) 4 ii) 3 iii)2 iv)1

State the sql command used to add a column to an existing table?


ALTER TABLE
ADD COLUMN

What will be the output of the following query?


Mysql> SELECT * FROM CUSTOMER WHERE CODE LIKE ‘_A%’
A) Customer details whose code’s middle letter is A
B) Customers name whose code’s middle letter is A
C) Customers details whose code’s second letter is A
D) Customers name whose code’s second letter is A

Sushma created a table named Person with name as char(20) and address as
varchar(40). She inserted a record with “Adithya Varman” and address as
“Vaanam Illam, Anna Nagar IV Street”. State how much bytes would have
been saved for this record.
i)(20,34) ii)(30,40) iii)(14,40) iv)14,34)

_____ gives the number of values present in an attribute of a relation.


a)count(distinct col) b)sum(col) c)count(col) d)sum(distinct col)

Assertion (A) : DROP is a DDL command


Reason(R ) : It is used to remove all the content of a database object
(I) (A) What constraint/s should be applied to the column in a table to make it
as alternate key?

(B) What constraint should be applied on a column of a table so that it


becomes compulsory to insert the value

(II)(A) Write an SQL command to assign F_id as primary key in the table
named flight
(B)Write an SQL command to remove the column remarks from the table
name customer.

(I) (A) UNIQUE ,NOT NULL

(B) NOT NULL (PRIMARY KEY CAN BE GIVEN MARK)

(II) (A) ALTER TABLE flight ADD PRIMARY KEY(F_id);

(B) ALTER TABLE CUSTOMER DROP REMARKS;

(A)
(i) To display number of different vehicle type from the table vehicle
(ii) To display number of records entered vehicle type wise whose minimum
cost is above 80
(iii)To set the cost as 45 for those vehicles whose cost is not mentioned
(iv) To remove all motor cycle from vehicle

i) SELECT COUNT(DISTINCT VTYPE) FROM VEHICLE;


ii) SELECT VTYPE,COUNT(*) FROM VEHICLE GROUP BY VTYPE
HAVING MIN(COST)>80;
iii) UPDATE VEHICLE SET COST=45 WHERE COST IS NULL
iv) SELECT OWNER ,VTYPE,CONTACT FROM VEHICLE WHERE
OWNER LIKE “P%”;

(B) (i) SELECT VTYPE,AVG(COST) FROM VEHICLE GROUP BY


VTYPE;
(ii) SELECT OWNER ,VTYPE,CONTACT FROM VEHICLE WHERE
OWNER LIKE “P%”;
(iii)SELECT COUNT(*) FROM VEHICLE WHERE COST IS NULL;
(iv) SELECT MAX(COST) FROM VEHICLE;

i)
+---------------------+-----------------+
| VTYPE | AVG(COST) |
+----------------------+-----------------+
| CAR | 65.0000 |
| truck | 125.0000 |
| Moter Cycle | NULL |
| SUV | 65.0000 |
| MOTOR CYCLE | NULL |
+----------------------+-----------------+
ii)
+--------------------+----------------------+------------------+
| OWNER | VTYPE | CONTACT |
+---------------------+----------------------+-----------------+
| Prem Sharma | Moter Cycle | 9987654321 |
| PRIYA REDDY | MOTOR CYCLE | 9123456789 |
+---------------------+----------------------+-----------------+
iii)
+---------------+
| COUNT(*) |
+--------------+
|2|
+--------------+
iv)
+-----------------+
| MAX(COST) |
+-----------------+
| 125 |
+-----------------+
i) To display airport name, city, flight id, flight number corresponding flights
whose departure is from delhi
ii) Display the flight details of those flights whose arrival is BOM, MAA or
CCU
iii) To delete all flights whose flight number starts with 6E.
iv) (A) To display Cartesian Product of two tables

(B) To display airport name,city and corresponding flight number

i) select airports.a_id,city,f_id,F_no from flights,airports where


flights.f_id=airports.a_id and departure="DEL";
ii) select * from flights where arrival="bom" or arrival="Maa" or
arrival="ccu";
iii) delete from flights where F_no like "6E%";
iv) (A) select * from flights,airports;
(b) select airports.a_id,city,flights.f_id from flights,airports where
airports.a_id=flights.a_id;

You might also like