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

ESP Suggested Q Ans

The document discusses a SQL query that counts the number of rows for each unique value in the name column after grouping the rows by name. It first creates a sample table with four rows and three distinct names, then performs a SELECT query with COUNT(*) and GROUP BY to count the rows for each name, returning two rows for 'abc', and one row each for 'bcd' and 'cde'.

Uploaded by

Draksha
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)
16 views

ESP Suggested Q Ans

The document discusses a SQL query that counts the number of rows for each unique value in the name column after grouping the rows by name. It first creates a sample table with four rows and three distinct names, then performs a SELECT query with COUNT(*) and GROUP BY to count the rows for each name, returning two rows for 'abc', and one row each for 'bcd' and 'cde'.

Uploaded by

Draksha
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/ 14

ESP Suggested Q.

Ans (2)

1. CREATE TABLE temp


(
id INT,
name VARCHAR(100)
);
INSERT INTO temp VALUES (1, "abc");
INSERT INTO temp VALUES (2, "abc");
INSERT INTO temp VALUES (3, "bcd");
INSERT INTO temp VALUES (4, "cde");

SELECT Count(*)
FROM temp
GROUP BY name;

To determine the result of the SQL query provided, let's break down what each
part does:

1. Creating the Table:

CREATE TABLE temp


(
id INT,
name VARCHAR(100)
);

This SQL statement creates a table named temp with two columns: id of
type INT and name of type VARCHAR(100) .

2. Inserting Data into the Table:

INSERT INTO temp VALUES (1, "abc");


INSERT INTO temp VALUES (2, "abc");
INSERT INTO temp VALUES (3, "bcd");
INSERT INTO temp VALUES (4, "cde");

ESP Suggested Q. Ans (2) 1


These INSERT statements add rows of data into the temp table. The table will
look like this after insertion:

id name

1 abc

2 abc

3 bcd

4 cde

3. Executing the SELECT Query:

SELECT Count(*)
FROM temp
GROUP BY name;

This SELECT query retrieves the count of rows ( Count(*) ) for each unique
value in the name column. The GROUP BY name clause ensures that rows are
grouped based on the name column.

4. Result Analysis:

There are two distinct names in the name column: "abc" , "bcd" , and
"cde" .

The GROUP BY name clause will group rows with the same name value
together.

For "abc" , there are 2 rows.

For "bcd" , there is 1 row.

For "cde" , there is 1 row.

5. Output:
The query will return:

Count(*)
-------
2
1
1

ESP Suggested Q. Ans (2) 2


This means:

There are 2 occurrences of "abc" in the name column.

There is 1 occurrence of "bcd" in the name column.

There is 1 occurrence of "cde" in the name column.

Therefore, the output of the query will be:

Count(*)
-------
2
1
1

2. Suppose (A, B) and (C,D) are two relation schemas. Let r1 and r2 be
the corresponding relation instances. B is a foreign key that refers to C
in r2. If data in r1 and r2 satisfy referential integrity constraints, which
of the following is ALWAYS TRUE?

Answer : (A)

ESP Suggested Q. Ans (2) 3


3. Which of the following is TRUE?
(A) Every relation in 2NF is also in BCNF
(B) A relation R is in 3NF if every non-prime attribute of R is fully
functionally dependent on every key of R
(C) Every relation in BCNF is also in 3NF
(D) No relation can be in both BCNF and 3NF

Answer (C)

ESP Suggested Q. Ans (2) 4


4. Consider the tables A, B and C. How many tuples does the result of
the following SQL query contain?

Table A
Id Name Age
----------------
12 Arun 60
15 Shreya 24
99 Rohit 11

Table B
Id Name Age
----------------

ESP Suggested Q. Ans (2) 5


15 Shreya 24
25 Hari 40
98 Rohit 20
99 Rohit 11

Table C
Id Phone Area
-----------------
10 2200 02
99 2100 01

SELECT A.id
FROM A
WHERE A.age > ALL (SELECT B.age
FROM B
WHERE B. name = "arun")

(A) 4 (B) 3 (C) 0 (D) 1

Answer (B)

5.

ESP Suggested Q. Ans (2) 6


SELECT Count(*)
FROM ( (SELECT Borrower, Bank_Manager
FROM Loan_Records) AS S
NATURAL JOIN (SELECT Bank_Manager,
Loan_Amount
FROM Loan_Records) AS T );
(A) 3
(B) 9
(C) 5
(D) 6

Answer (C)

ESP Suggested Q. Ans (2) 7


6.

ESP Suggested Q. Ans (2) 8


(A) 1, 0
(B) 1, 2
(C) 1, 3
(S) 1, 5

Answer C

7. What is the difference between TRUNCATE, DELETE and DROP statements?

ESP Suggested Q. Ans (2) 9


In SQL, the DELETE, DROP, and TRUNCATE commands are used to manipulate
data in a database:

DELETE
A Data Manipulation Language (DML) command that removes specific rows
from a table based on conditions, while keeping the table structure
intact. For example, DELETE FROM Employee WHERE EmpID=15 .

DROP

A Data Definition Language (DDL) command that deletes an entire table,


including its structure, data, indexes, triggers, constraints, and permission
specifications. For example, DROP Table Employee . DROP is permanent and
cannot be recovered without a backup.

TRUNCATE

A DDL command that removes all rows from a table, but preserves its
structure. TRUNCATE releases allocated storage space and cannot be
rolled back. For example, TRUNCATE TABLE Employee .

8. Draw the B-tree of order 3 and order 4 created by inserting the following
data arriving in sequence 92 24 6 7 11 8 22 4 5 16 19 20 7

ESP Suggested Q. Ans (2) 10


ESP Suggested Q. Ans (2) 11
ESP Suggested Q. Ans (2) 12
ESP Suggested Q. Ans (2) 13
ESP Suggested Q. Ans (2) 14

You might also like