Solved Question Bank_Database concepts
Solved Question Bank_Database concepts
CLASS XII
CBSE SOLVED QUESTION BANK
DATABASE CONCEPTS AND SQL
3) In which datatype the value stored is padded with spaces to fit the specified
length. (A) DATE (B) VARCHAR (C) FLOAT (D) CHAR
Ans) D
10) Give one difference between alternate key and candidate key.
Ans) All keys that have the properties to become a primary key are candidate
keys. The candidate keys that do not become primary keys are alternate keys.
11) Fill in the blank: ______ command is used to remove primary key from the
table in SQL. (a) update (b)remove (c) alter (d)drop
Ans) c
12) Which of the following commands will delete the table from MYSQL
database? (a) DELETE TABLE (b) DROP TABLE (c) REMOVE TABLE (d) ALTER
TABLE
Ans) b
13) Fill in the blank: _________ is a non-key attribute, whose values are
derived from the primary key of some other table.
(a) Primary Key (b) Foreign Key (c) Candidate Key (d) Alternate key
Ans) b
14) Fill in the blank: The SELECT statement when combined with __________
clause, returns records without repetition. (a) DESCRIBE (b) UNIQUE (c)
DISTINCT (d) NULL
Ans) c
15) Which function is used to display the total number of records from table
in a database? (a) sum(*) (b) total(*) (c) count(*) (d) return(*)
Ans) c
18) In SQL, which command will be used to add a new record in a table ?
(A) UPDATE (B) ADD (C) INSERT (D) ALTER TABLE
Ans) D
19)Mr. Ravi is creating a field that contains alphanumeric values and fixed
lengths. Which MySQL data type should he choose for the same ? 1
(A) VARCHAR (B) CHAR (C) LONG (D) NUMBER
Ans) B
2 mark questions
21) A) What constraint should be applied on a table column so that duplicate values
are not allowed in that column, but NULL is allowed.
Ans) Unique
B) Write an SQL command to remove the Primary Key constraint from a table,
named MOBILE. M_ID is the primary key of the table
Ans) alter table mobile drop primary key;
22)A) What constraint should be applied on a table column so that NULL is not
allowed in that column, but duplicate values are allowed.
Ans) not null
B) Write an SQL command to make the column M_ID the Primary Key of an
already existing table, named MOBILE.
Ans) alter table mobile add primary key (M_ID);
23)Ms. Shalini has just created a table named “Employee” containing columns
Ename, Department and Salary. After creating the table, she realized that she
has forgotten to add a primary key column in the table. Help her in writing an
SQL command to add a primary key column EmpId of integer type to the table
Employee. Thereafter, write the command to insert the following record in the
table: EmpId- 999 Ename- Shweta Department: Production Salary: 26900
Ans) ALTER TABLE Employee ADD EmpId INTEGER PRIMARY KEY;
INSERT INTO Employee VALUES("Shweta","Production",26900,999);
INSERT INTO Employee(EmpId,Ename,Department,Salary)
VALUES(999,"Shweta","Production",26900);
29)Write the output of the queries (a) to (d) based on the table, Furniture given
below:
OR
Which field will be considered as the foreign key if the tables MOVIEDETAILS
and SCHEDULE are related in a database?
Ans) MOVIEID
32)I) A table, ITEM has been created in a database with the following fields:
ITEMCODE, ITEMNAME, QTY, PRICE Give the SQL command to add a new
field, DISCOUNT (of type Integer) to the ITEM table.
Ans) ALTER TABLE Item ADD (Discount INT);
ii) Categorize following commands into DDL and DML commands? INSERT
INTO, DROP TABLE, ALTER TABLE, UPDATE...SET
Ans) DDL: DROP TABLE, ALTER TABLE DML: INSERT INTO, UPDATE. ..SET
36)Write the output of the SQL queries (a) to (d) based on the table TRAVEL
given below :
ii) SELECT T_ID, FARE FROM TRAVEL WHERE T_DATE LIKE '2021-12-%' ;
Ans)
T_ID Fare
101 4500
102 4000
37)Write the output of the SQL queries (a) and (b) based on the following two
tables FLIGHT and PASSENGER belonging to the same database :
(i) Identify and write the name of the Candidate Keys in the given table BATSMEN.
Ans) PNO and Name
(ii) How many tuples are there in the given table BATSMEN ?
Ans) 5
3 mark questions
44)Consider the table CLUB given below and write the output of the SQL queries
that follow
(i) SELECT COUNT(DISTINCT SPORTS) FROM CLUB;
Count(distinct(sports))
4
(ii) SELECT CNAME, SPORTS FROM CLUB WHERE DOAPP<"2006-04-30"
AND CNAME LIKE "%NA";
CNAME SPORTS
AMINA CHESS
(iii) SELECT CNAME, AGE, PAY FROM CLUB WHERE GENDER = "MALE" AND
PAY BETWEEN 1000 AND 1200;
CNAME AGE PAY
AMRIT 28 1000
VIRAT 35 1050
i) SELECT Department,
avg(salary) FROM Teacher
GROUP BY Department;
Ans)
ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher;
Ans)
iv) SELECT Name, Place FROM Teacher T, Placement P WHERE Gender='F' and
T.Department=P.Department;
Ans
48)Charu has to create a database named MYEARTH in MYSQL. She now needs to
create a table named CITY in the database to store the records of various cities
across the globe. The table CITY has the following structure:
ii) SELECT NAME, SALARY FROM EMPLOYEE WHERE NAME LIKE 'A%';
Ans)
NAME SALARY
Akhtar 125000
Alex 75000
iii) SELECT NAME, DOJ FROM EMPLOYEE WHERE SALARY BETWEEN 100000 AND
200000;
NAME DOJ
Ranjan 2015-01-21
Akhtar 2015-02-01
Muneera 2018-08-19
(b) Write the name of the command to display the structure of a table in a database.
Ans) desc or describe
51)Navdeep creates a table RESULT with a set of records to maintain the marks
secured by students in Sem1, Sem2, Sem3, and their divisions. After the
creation of the table, he entered data of 7 students in the table.
9) Rashmi has forgotten the names of the databases, tables and the structure
of the tables that she had created in Relational Database Management System
(RDBMS) on her computer.
(a) Write the SQL statement to display the names of all the databases
present in RDBMS application on her computer.
Ans) show databases;
(b) Write the statement which she should execute to open the database
named "STOCK".
Ans) use stock;
(c)Write the statement which she should execute to display the structure of the table
"ITEMS" existing in the above opened database "STOCK".
Ans) desc items;
52) Consider the table Stationery given below and write the output of the SQL queries that follow
(ii) SELECT ITEMNO, ITEM FROM STATIONERY WHERE DISTRIBUTOR = "Classic Plastics"
AND PRICE > 10;
Ans)
ITEMNo ITEM
402 Gel Pen Premium
406 Gel Pen Classic
iii) SELECT ITEM, QTY * PRICE AS "AMOUNT" FROM STATIONERY WHERE ITEMNO = 402;
Ans)
ITEM Amount
Gel Pen Premium 3000
Based on the given table, write SQL queries for the following :
(i) Add a primary key to a column name Vcode.
Ans) alter table ren_cab add primary key (VCode);
ii) Increase the charges of all the cabs by 10%.
Update Rent_cab set charges =1.1*charges;
(b) Write the output of the queries (i) to (iv) based on the table, GARMENT given below
54) Write the output of any three SQL queries (i) to (iv) based on the tables
COMPANY and CUSTOMER given below :
4 mark questions
55)
III) Select o_id, c_name, product, quantity, price from orders where price
between 1500 and 12000;
Ans)
56) 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.
I) To display complete details (from both the tables) of those Faculties whose
salary is less than 12000
Ans) select * from faculty natural join courses where salary<12000;
OR
Select * from FACULTY, COURSES where Salary < 12000 and
facuty.f_id=courses.f_id;
II) To display the details of courses whose fees is in the range of 20000 to
50000 (both values included).
Ans) Select * from courses where fees between 20000 and 50000;
iii) To increase the fees of all courses by 500 which have "Computer" in their
Course names.
Ans) Update courses set fees=fees+500 where CName like '%Computer%';
iv) (A) To display names (FName and LName) of faculty taking System Design.
Ans) Select FName, LName from faculty natural join courses where
Came="System Design";
Or
Select FName, LName from faculty, courses where Came="System Design"
and facuty.f_id=courses.f_id;
ii) If two columns are added and 2 rows are deleted from the table result, what
will be the new degree and cardinality of the above table?
Ans) New Degree: 8 New Cardinality: 5
iii. Write the statements to: a. Delete the record of students securing IV division.
b. Add a column REMARKS in the table with datatype as varchar with 50 characters
ALTER TABLE RESULT ADD (REMARKS VARCHAR(50));
58)
Write SQL queries for the following:
(i) Display product name and brand name from the tables PRODUCT and
BRAND.
Ans) SELECT PName, BName product natural join brand;
(ii) Display the structure of the table PRODUCT.
Ans) DESC PRODUCT;
(iii) Display the average rating of Medimix and Dove brands
Ans) SELECT BName, AVG(Rating) FROM product natural join brand GROUP BY
BName where BName='Medimix' OR BName='Dove';
(iv) Display the name, price, and rating of products in descending order of rating.
Ans) SELECT PName, UPrice, Rating FROM PRODUCT ORDER BY Rating DESC;
59)Write queries (a) to (d) based on the tables EMPLOYEE and DEPARTMENT given
below:
60)Write SQL queries for (a) to (d) based on the tables CUSTOMER and
TRANSACT given below
a) Write the SQL statements to delete the records from table TRANSACT whose
amount is less than 1000.
Ans) delete from Transact where amount<1000;
b) Write a query to display the total AMOUNT of all DEBITs and all CREDITs.
Ans) select ttype,sum(amount) from transact group by ttype;
c) Write a query to display the NAME and corresponding AMOUNT of all
CUSTOMERs who made a transaction type (TTYPE) of CREDIT.
Ans) select name, amount from customer natural join transact where
ttype=’Credit’;
Or
Select name,amount from customer c, transact t where c.cno=t.cno and
ttype=’Credit’;
OR