SQL Flashcards

1
Q

What does SQL stand for?

A

Structured Query Language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Units of time are divided into two groups in SQL, list the groups.

A

year, month
day, hour, minute, second

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Distinguish between intra and inter relational constraints.

A

Intra - involve a single relation
Inter - involve multiple relations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the four different reaction policies.

A

cascade - propagate the change made in one table to linked tables.
set null - nullify the attributes in other tables
set default - assign the default value to referring attributes
no action - don’t allow change

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

T or F. SQL is a declarative language.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Give a basic SQL query structure.

A

select attribute, attribute
from table , table
where conditon x and condition y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When combining two tables in sql what must be included as condition in the where clause?

A

That the foreign key holds true. E.g. that taking_course is equal to course_code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When tables are joined along attributes X with the same name what is the syntax for the select?

A

select C.attribute
from table C, table P
where condition x and C.X = P.X

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give an example of an aggregate SQL query.

A

count()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Differentiate between count(*), count(distinct) and count(all).

A

count(*) selects all rows
count(distinct) selects all unique rows
count(all) selects all rows that have not null values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Is the following query valid?
select FirstName, Surname, max(Salary)
from EMPLOYEE

A

Query is invalid. Syntax does not allow aggregate functions and attribute expressions together in select clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the group by clause?

A

Allows applying aggregate operators to specific subsets of rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the rule for the group by clause syntax?

A

The attributes that appear in the target list must be a subset of the attributes used in the group by clause. I.e. all attributes that appear in select must appear in group by.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the having clause?

A

Having clause added after group by clause to retain only subsets that satisfy a group predicate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Rule for having clause syntax.

A

Only aggregate operators are allowed to appear in the having clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does keyword all mean when added to the SQL keyword union?

A

Keep duplicates.

17
Q

What is the short of =any?

A

in

18
Q

What is the short of <>all?

A

not in

19
Q

What does the exist operator return?

A

Returns true only if nested query does not produce a null result.

20
Q

Explain insert, delete and update.

A

Insert: insert rows
Delete: delete rows
Update: Change attribute values of the rows of a table

21
Q

What are the two categories of constraints?

A

Immediate
Deferred

22
Q

Give examples of how restraints can be placed on (a) a single relation with a single tuple. (b) a single relation with multiple rows of the same relation. (c) a single relation with aggregation constraints. and (d) On multiple relations

A

(a) On a single tuple: Attribute constraints, multiple-attribute constraints
(b) On multiple rows of the same relation: Functional dependencies, Cardinality Constraints
(c) Aggregation Constants. E.g. The average salary of employees in department must be greater than 30
(d) On multiple relations: foreign keys.

23
Q

What is the check clause?

A

The check clause can be used to express arbitrary constraints during schema definition.

24
Q

What is assertion? Give sample code.

A

Assertion allows the definition of constraints outside of table definitions.
create assertion AssertionName
check (condition)

25
Q

What are views? What rule applies to multiple views?

A

Views are virtual tables whose contents depend on contents of other tables.

They cannot be mutually dependent.