0% found this document useful (0 votes)
6 views4 pages

Relational Database and SQL

The document is an answer key for a Unit Test in Computer Science focusing on SQL and database concepts. It includes true/false questions, SQL command writing, and differentiations between various database terms and constraints. Additionally, it covers practical SQL queries related to database operations and table manipulations.

Uploaded by

sumanishasuresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Relational Database and SQL

The document is an answer key for a Unit Test in Computer Science focusing on SQL and database concepts. It includes true/false questions, SQL command writing, and differentiations between various database terms and constraints. Additionally, it covers practical SQL queries related to database operations and table manipulations.

Uploaded by

sumanishasuresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

VELAMMAL BODHI CAMPUS

COMPUTER SCIENCE(083)

UNIT TEST-1(ANSWER KEY)

1. State True or False 1


SQL is a database language
True
2. Write the full form of SQL and RDBMS 1
SQL- STRUCTURED QUERY LANGUAGE
RDBMS – RELATIONAL DATABASE MANAGEMENT SYSTEM
3. List out any two database software names 1
SQL,ORACLE,MONGODB,SQLITE
4. Another name for row in relational database is -------- 1
a.column b.attribute c.domain d.tuple
5. What is called as a relation in relational database? 1
Table is otherwise called as relation which is set of rows and columns
6. Write the SQL command to list out the databases available in the system. 1
SHOW DATABASES;
7. What is the format used for storing date using date datatype? 1
(a) dd-mm-yy (b) dd-mm-yyyy (c) mm-dd-yyyy (d) yyyy-mm-dd
8. A table has initially 5 columns and 8 rows. Consider the following sequence of operations 1
performed on the table –
i. 8 rows are added
ii. 2 columns are added
iii. 3 rows are deleted
iv. 1 column is added
What will be the cardinality and degree of the table at the end of above operations?
(a) 13,8 (b) 8, 13 (c) 14,5 (d) 5,8
9. I. A) What constraint should be applied on a table column so that duplicate values are not 2
allowed in that column, but NULL is allowed.
UNIQUE
OR
B) What constraint should be applied on a table column so that NULL is not allowed in that
column, but duplicate values are allowed.
NOT NULL
II. 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.
ALTER TABLE MOBILE DROP PRIMARY KEY;
OR
B) Write an SQL command to make the column M_ID the Primary Key of an already existing
table, named MOBILE.
ALTER TABLE MOBILE ADD PRIMARY KEY(M_ID);
10. Categorize the following commands as DDL or DML: 2
INSERT, UPDATE, ALTER, DROP
DDL-ALTER,DROP
DML-INSERT UPDATE
11. Write the advantages of database over traditional file keeping system 2
1.ELIMINATION OF DATA REDUNDANCY
2.ELIMINATION OF DATA INCONSISTENCY
3.EASY DATA ACCESS
4.DATA IS SECURED
5.DATA CAN BE SHARED
12. Observe the following table and answer the parts (i) and (ii): 2
TABLE:STORE
ITEMCODE ITEM QTY RATE
10 GEL PEN CLASSIC 1150 25
11 SHARPENER 1500 10
12 BALL PEN 1600 12
13 ERASER 1600 5
15 BALL PEN 500 20
(i) In the above table, can we have Qty as primary key. [Answer as yes/no]. Justify
your answer.
NO.PRIMARY KEY SHOULDN’T BE REPEATED.
(ii) Differentiate between candidate key and alternate key with an example table.
KEYS ELIGIBLE TO BECOME PRIMARY KEY –CANDIDATE KEYS
CANDIDATE KEY NOT PRIMARY KEY – ALTERNATE KEY
ONE EG. TABLE
13. Differentiate between CHAR and VARCHAR with an example. 2

ONE EXAMPLE.
14. Differentiate between COUNT() and COUNT(*) in sql with example. 2
15. Write SQL queries for the following statements 3
i) Select the created database ITEMDB
USE ITEMDB;
ii) Create the table STATIONERY with the following structure

CREATE TABLE STATIONERY(ITEMNO INT(11), ITEMNAME VARCHAR(15),


PRICE FLOAT,QTY INT(11);
iii) Add the following row into the created table
(101,’soap’,90,100)
INSERT INTO STATIONERY VALUES(101,’soap’,90,100)

16. Consider the following tables – FACULTY and COURSES : 4


What will be the output of the following statement?
i. SELECT FID, MIN(SALARY), MAX(SALARY) FROM FACULTY GROUP BY
FID;
FID MIN(SALARY) MAX(SALARY)
F01 32000 32000
F03 15000 15000
F04 27000 27000
F05 30000 30000
ii. SELECT AVG(SALARY) FROM FACULTY WHERE FNAME LIKE '%E%';
AVG(SALARY)
28500
iii. SELECT COUNT(DISTINCT(FID)) FROM FACULTY;
COUNT(DISTINCT(FID))
4
iv. SELECT * FROM FACULTY WHERE SALARY BETWEEN 1500 AND 30000;
FID FNAME LNAME JOINDATE SALARY
F03 BHUMI GOEL 2001-08-10 15000
F04 NEHA VERMA 2000-05-17 27000
F05 MEENU SHARMA 2006-07-11 30000
17. Write the output of the queries (i) to (iv) based on the table Table: Employee 4

i SELECT NAME, PROJECT FROM EMPLOYEE ORDER BY NAME DESC;

ii SELECT NAME,SALARY FROM EMPLOYEE WHERE NAME LIKE 'A%';

iii SELECT MAX(DOB), MIN(DOJ) FROM EMPLOYEE;


MAX(DOB) MIN(DOJ)
1996-11-15 2015-01-21
iv SELECT * FROM EMPLOYEE WHERE PROJECT = 'P01';
18. Consider the table ORDERS as given below 4

Note: The table contains many more records than shown here.
Write the following queries:
(I) Delete the products which have quantity less than 2.
DELETE FROM ORDERS WHERE QUANTITY<2;
(II) Increase the price of all products by 5%.
UPDATE ORDERS SET PRICE=PRICE+5/100* PRICE;
(III) To display the customer names without repetition from the Orders table.
SELECT DISTINCT C_NAME FROM ORDERS;
(IV) Display the sum of Price of all the orders for which the quantity is not known.
SELECT SUM(PRICE) FROM ORDERS WHERE QUANTITY IS NULL;

You might also like