Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
What is the difference between a Facts Table (or a Base table) and a
Dimension Table? (1 mark)
ANSWER:
Fact table in a data warehouse consists of facts and/or measures. The nature of data in a fact table is
usually numerical.
On the other hand, dimension table in a data warehouse contains fields used to describe the data in fact
tables. A dimension table can provide additional and descriptive information (dimension) of the field of a fact
table.
4. What is the difference between WHERE clause and HAVING clause? (1 mark)
ANSWER:
6. What is a Self Join? Mention one use of Self Join using an example. (1+2=3
marks)
ANSWER:
A self join is a join in which a table is joined with itself (which is also called Unary relationships), specially
when the table has a FOREIGN KEY which references its own PRIMARY KEY.
Example:
SELECT e.name EMPLOYEE, m.name MANAGER
FROM EMPLOYEE e, EMPLOYEE m
WHERE e.mgr_id = m.id (+)
9. What's the difference between a primary key and a unique key? (1 mark)
ANSWER: Primary key doesn't allow NULLs, but unique key allows one NULL
only.
10.Values in Primary key can be updated or Modified. (True/False)
Explain your answer. (1 mark)
ANSWER:
False
The value of the primary key in the table cannot be updated due to the Parent child relationships, as the
primary key in one table (parent table) would a foreign key in another table(child table).
Unless and until the values in the child table are deleted, the values in the parent tables cannot be updated
or modified.
ANSWER:
A FOREIGN KEY is a column or a group of columns whose values are derived
from the Primary key or the unique key of some other table. Foreign keys
represent relationships between tables, i.e., foreign key constraints are used
to enforce referential integrity.
13.What is a Composite Primary Key? (1 mark)
ANSWER:
Composite primary key is a primary key, which is made up of two or more
fields (columns).
14.What is the difference between IN and EXISTS? (2 marks)
ANSWER:
The IN operator returns a row if a WHERE conditioned table.field value
matches a list of IN values. IN is typically used as part of a main query or in
conjunction with a subquery.
The EXISTS operator returns all main query rows if the subquery contains any
rows. EXISTS is only used in conjunction with a subquery.
Performance wise, EXISTS works faster than IN
15.What is a view? (1 mark)
ANSWER:
A view is a virtual table based on the result-set of an SQL statement.
16.Which of the below operations are valid for VIEWS? (1 mark)
a. INSERT
b. UPDATE
c. DELETE
d. DROP
ANSWER: a,b,c,d
All operations DROP is valid for both read-only and updatable views.
INSERT, DELETE and UPDATE are valid only on updatable views defined from a single table
19.What will be the result of the below query? Explain your answer. (1 mark)
SELECT CASE WHEN NULL = NULL THEN 'Yes' ELSE 'No' END AS RESULT
ANSWER:
Result will always be No. The correct syntax for operation on NULL values is
IS NULL
20.What will be the result of the below query? (1 mark)
SELECT max(Emp_Salary) FROM Emp_Detail WHERE Emp_Salary NOT
IN(SELECT max(Emp_Salary) FROM Emp_ Detail)
ANSWER: Second highest salary
21.What is the output of below query for the below tableA? (1 mark)
custome transactio transaction_ amount
r_id
n_id
date
(USD)
101 a001
1/1/2014
5
102 a002
2/2/2014
10
101 a003
4/2/2014
4
103 a004
8/5/2014
10
104 a005
10/7/2014
100
105 a006
11/8/2014
150
101 a007
12/8/2014
20
102 a008
12/12/2014
14
SELECT Customer_id
FROM TableA
WHERE SUM(amount) >50
GROUP BY Customer_id
ANSWER: Error as aggregate function cannot be used in the WHERE clause
23.Write a single SELECT statement to select all the customers who have done
more than 25 USD of total transaction in the year 2014. (3 marks)
custome
transactio
transaction_
amount
r_id
101
102
101
103
104
105
101
102
103
106
107
108
109
110
n_id
a001
a002
a003
a004
a005
a006
a007
a008
a009
a010
a011
a012
a013
a014
date
(USD)
1/1/2013
2/2/2014
4/2/2014
8/5/2014
10/7/2014
11/8/2012
12/8/2014
12/12/2014
12/12/2014
14/12/2014
6/9/2013
7/10/2014
10/10/2014
12/11/2014
5
10
4
10
100
150
20
14
30
10
25
15
45
30
ANSWER:
SELECT customer_id
FROM <Transaction_table>
WHERE transaction_date BETWEEN 01/01/2014 AND 31/12/2014
GROUP BY 1 HAVING SUM(amount)>=25.00
25.What is the output of the below SQL code on the below table? (1 mark)
TableA
Student_
ID
1
2
3
4
Name
John
Mary
Mohan
Kiran
Score
86.2
78.5
68.9
82.9
SELECT
Name,
CAST(Score AS char(3)) Char_Score
From TableA
ANSWER:
Name
John
Char_Score
86.
Mary
78.
Mohan
68.
Kiran
82.