SQL: A Commercial Database Language Flashcards

1
Q

The name SQL is derived from

A

Structured Query Language

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

Sequel was originally called ______.

A

SEQUEL ( for Structure English QUEry Language).

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

What does it mean that SQL is a comprehensive database language?

A

It has statements for data defintion, query and update (in this sense it is both a DDL and a DML). In addiotion, it has facitilities for defining views, for specifying security anduthorization, for defining integrity constaints, and for specifying transaction controls. It also has rules for embedding SQL statements into a general-purpose programming language.

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

The SQL language provides a high-level declarative language interface meaning

A

The SQL language provides a high-level declarative language interface meaning the user specifies what the result is to be and leaves the decisions on how to execute the query to the DBMS.

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

The terms table, row, and column are used in SQL in documents for ____, ____ and ____ respectively.

A

table = relation

row = tuple

column = attribute

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

is SQL case sensitive?

A

No. It treats upper and lower case letters as the same letter. Only inside quotes does SQL make a distinction between upper and lower case letters.

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

The concept of ____ is used in SQL to group together constructs that belong to the same database application

A

schema

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

A schema includes ______ such as tables constraints, view, domains, authorization grants and other constructs.

A

schema elements

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

A SQL schema is identified by a schema name and includes an _______ to indicate the user who owns the scema. In addition, it can include _______ for every element in the schema.

A

authorization identifier ; descriptors

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

Write a SQL statement that creates a schema called COMPANY owned by a user with authorization identifier JSMITH

A

CREATE SCHEMA COMPANY AUTHORIZATION JSMITH;

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

The concept of a ______ is used in SQL to denote a named collection of schemas.

A

catalog

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

A catalog always contains a special schema called _____. This schema provides information on all the schemas in the catalog and all the element descriptors in these schemas.

A

INFORMATION_SCHEMA

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

True or False: Some elements (e.g. domain definitions) can be shared by schemas in the same catalog.

Integrity constraints can be defined between relations only if they do not exist in schedmas of the same catalog

A

True.

False. Integrity constraints can be defined between relations only if they exist in schemas of the same catalog.

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

What data types are included in SQL?

A

numerics, character-string, bit-string, data and time.

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

What are the numeric types in SQL and how are they specified?

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

What are the character string data types in SQL and how are they specified?

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

What are the bit string data types in SQL and how are they specified?

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

What are the data and time data types in SQL and how are they specified?

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

How do you create a domain in SQL on SSN_TYPE to be a character data type consisting of 9 characters?

A

CREATE DOMAIN SSN_TYPE AS CHAR(9);

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

A create domain statement can have an optional _______ and an optional

_____________.

.

A

default specification ; list of constraints

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

What does the CREATE TABLE command do?

A

The CREATE TABLE command is used to specify a new relation, its attributes, their data types and constraints.

The key, entity integrity and referential integrity constraints can be specified within a CREATE TABLE statement or later using the ALTER TABLE command.

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

Create a relation named department with attributes: DNAME, DNUMBER, MGRSSN, MGRSTARTDATE. The primary key is DNUMBER and the MGRSSN and EMPLOYEE are foreign keys. DNAME is a secondary key (unique). Write a command to create this relation.

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

A constraint can be given a name following the keyword ________. Giving names to constraints, is:

A) optional but is a good practice to follow.

B) necessary and a bad practice to follow.

C) unnecessary but a bad practice to follow.

D) necessary and a good practice to follow.

A

CONSTRAINT;

A) optional but is a good practice to follow.

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

True or False: The names of some of the constraints within a particular can match (not unique).

A

False. The names of all constraints withing a particular schema must be unique. A constraint name can be used to drop a constraint (and replace it later by another constraint).

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

What is SQL’s default policy for any modificiations that violate the referential integrity constraint?

A

Any modifications violating the referential integrity constraints is rejected by the system.

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

In SQL, the schema designer can specify the action of a referenced primary key value, by attaching a referential triggered action clause to a foreign key constraint.

What are three options?

A

SET NULL, CASCADE, SET DEFAULT

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

In SQL, the schema designer can specify the action of a referenced primary key value, by attaching a referential triggered action clause to a foreign key constraint.

The options include SET NULL, CASCADE, SET DEFAULT.

They can be qualified on either ______ or ______.

.

A

ON DELETE ; ON UPDATE

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

How would you specify a constraint called EMPPK that enforces for the EMPLOYEE relation’s primary key is SSN?

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

How would you specify a constraint called EMPSUPERFK that enforces for the EMPLOYEE relation’s primary foreign key is SUPERSSN (references relation EMPLOYEE), sets the value to null on delete, and cascades the changes on update?

How would you specify a constraint called EMPDEPTFK that enforces for the EMPLOYEE foreign key references DEPARTMENT, on delete sets the value to the default value of 4, and on update cascades the changes?

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

How would you specify a constraint called EMPDEPTFK that enforces for the EMPLOYEE foreign key references DEPARTMENT, on delete sets the value to the default value of 4, and on update cascades the changes?

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

Can the name of a schema be explicitly specified in the definition of a table?

A

Yes

CREATE TABLE COMPANY.DEPARTMENT….

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

A schema can be deleted using the _______ command. It has two options: _____ and _____.

A

DROP SCHEMA; CASCADE; RESTRICT

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

For DROP SCHEMA, what happens if RESTRICT is specified ?

A

The operation will fail if the schema if nonempty; otherwise it will be succeed and the schema will be destroyed.

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

For DROP SCHEMA, what happens if CASCADE is specified ?

A

If CASCADE is spedicifed the operation will always succeed.

DROP SCHEMA COMPANY CASCADE;

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

A table can be deleted using the _________ command. Two options: _____ and _____.

A

DROP TABLE, CASCADE, RESTRICT

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

For DROP TABLE, what happens if RESTRICT is specified ?

A

If RESTRICT is specified, the operation will succeed only if the table is not referenced in any constraints or views.

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

For DROP TABLE, what happens if CASCADE is specified ?

A

If CASCADE is specified, the operation will always succeed and propogate to all constraints and views that reference the table.

DROP TABLE DEPENDENT CASCADE;

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

How do you add a column to relation EMPLOYEE with attribute name JOB and domain of variable char of length 12?

A

ALTER TABLE COMPANY.EMPLOYEE ADD JOB VARCHAR(12);

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

ALTER TABLE COMPANY.EMPLOYEE ADD JOB VARCHAR(12) NOT NULL;

What does this command do?

A

This command creates a new attribute for relation EMPLOYEE called JOB which is a character string with variable length up to 12 NOT NULL forces this attribute to have a value. A DEFAULT clause can also be specified. If no such clause is specified the new attribute will have NULLs in all the tuples of the relation after the command is executed.

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

How to drop a column called ADDRESS from relation EMPLOYEE with so that the deletion is always successful and propogates to all constraints and views that referencee the column?

A

ALTER TABLE COMPANY.EMPLOYEE DROP ADDRESS CASCADE;

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

When dropping a column, what is the difference between CASCADE and RESTRICT?

A

The CASCADE option: all constraints and views that reference the column are dropped from the schema.

The RESTRICT option. the command is successful only if no views or constraints reference the column.

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

How would you drop a default clause in a column called MGRSSN for relation DEPARTMENT in the COMPANY SCHEMA?

A

ALTER TABLE COMPANY.DEPARTMENT ALTER MGRSSN DROP DEFAULT;

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

How would you add a default clause to a column called MGRSSN in relation DEPARTMENT in the COMPANY schema such that the default MGRSSN is now ‘33344555’?

A

Adding a default clause in a column:

ALTER TABLE COMPANY.DEPARTMENT ALTER MGRSSN SET DEFAULT ‘33344555’;

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

What must a constraint have in order to be dropped?

A

To be dropped a constraint must have a name.

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

Write the command that drops the constrain from relation EMPLOYEE called EMPSUPERFK such that all foreign key definitions that reference the candidate key will be dropped too.

A

ALTER TABLE COMPANY.EMPLOYEE DROP CONSTRAINT EMPSUPERFK CASCADE;

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

When dropping a CONSTRAINT, CASCADE and RESTRICT have meaning only if _____________.

A

the constraint is specified, all the foreign key definitions that reference the candidate key will be dropped too.

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

Write a command that adds a constraint called EMPSUPERFK that enforces the foreign key SUPERSSN references an EMPLOYEE.

A

ALTER TABLE COMPANY.EMPLOYEE ADD CONSTRAINT EMPSUPERFK FOREIGN KEY SUPERSSN REFERENCES EMPLOYEE;

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

True or False: When adding a constraing using ALTER TABLE, the constraint to be created can be named or unnamed.

A

True.

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

What is the problem with these table definitions?

A

The problem is taht either EMPLOYEE or DEPARTMENT table has to be defined first.

In both cases, the system will issue an error message.

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

What is a possible solution to the problem in this code?

A

The chicken and egg problem in this code can be solves by postponing the foreign-key constraint in the first table. For instance, if CREATE TABLE EMPLOYEE is executed first, we should not have the foreign key clause FOREIGN KEY (DNO) … in the statement.

After CREATE TABLE DEPARTMENT has been process, we can add the desired constraint to employee using the ALTER TABLE command:

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

If we want to populate our COMPANY database, we face another chicken and egg problem because insertions of EMPLOYEE’s with non NULL DNO’s will be rejected because it violates the foreign key constraint:

MRGSSN references EMPLOYEE(SSN). What is a solution to this problem?

A

One solution is to initially replace DNO component in all tuples to be inserted in the EMPLOYEE relation with NULL. Then, when DEPARTMENT is populated with appropriate tuples, we can scan relation EMPLOYEE and replace NULLs with valid department number. This solution is awkward and error-prone. A better solution is to use transactions and deferred checking of integrity constraints.

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

SQL has one basic statement for retrieving information from a database; the _______.

A

SELECT statement

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

The SELECT statement in SQL is (same/ not same) as the SELECT operation of relational algebra.

A

Not the same. The Important distinction between SQL and the formal relational model : SQL allow a table (relation) to have two or more tuples that are identical in all their attribute values.

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

A SQL relation (table) is a multi-set (sometimes called a _____) of tuples; it is not a set of tuples.

A

bag

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

SQL relations can be constrained to be sets by specifying PRIMARY KEY or UNIQUE attributes in a table definition or by USING _____ option in a query.

A

DISTINCT

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

In a SELECT-FROM-WHERE block, SELECT takes an <attribute> as an argument. what does attribute list refer to ?</attribute>

A

attibute list is a list of attribute names whose values are to be retrieved by the query

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

In a SELECT-FROM-WHERE block, FROM takes a

as an argument. what does table list refer to ?

A

table list is a list of the relation names required to process the query.

58
Q

In a SELECT-FROM-WHERE block, WHERE takes a as an argument. What does condition refer to ?

A

cition is a conditional coolean expression that identifies the tuples to be retrieved by the query.

59
Q

What is a SELECT-FROM-WHERE block?

A

SELECT <attribute></attribute>

FROM

WHERE <condition></condition>

60
Q

Write the SQL query that retreives the birthdate and address of the employee(s) whose name is ‘John Smith’.

A

SELECT BDATE, ADDRESS

FROM EMPLOYEE

WHERE FNAME=’John’ AND

LNAME=’Smith’;

61
Q

Compare SELECT-PROJECT pair of relation algebra operations to SQL equivalent.

A

THE SELECT-clause specifies the projection attributes and the WHERE-CLAUSE specifies the selection condition. However the result of a SQL SFW query may contain duplicate tuples.

62
Q

Write the query that retrieves the name and address of all employees who work for the ‘Research’ department.

A

SELECT FNAME, LNAME, ADDRESS

FROM EMPLOYEE, DEPARTMENT

WHERE DNAME=’Research’ AND DNUMBER=DNO;

The WHERE-clause specifies the selection condition (corresponding to the selection operation in relational algebra) and a join condition (corresponding to the join operation in relational algebra).

63
Q

In SQL, we can use the same name for two (or more) attributes as long as the attributes are in _______.

A

different relations

64
Q

A query that refers to two or more attributes with the same name must qualify the attrivute name with the relation name by _____________.

A

prefixing the relation name the the attribute name.

65
Q

Write the SQLquery that lists the department names and their locations.

A

SELECT DEPARTMENT.DNAME, DEPT_LOCATIONS.DLOCATION

FROM DEPARTMENT, DEPT_LOCATIONS

WHERE DEPARTMENT.DNUMBER=DEPT_LOCATIONS.DNUMBER;

66
Q

Some queries need refer to the same relation twice. In this case, _____ are given to the relation name.

A

aliases

67
Q

Write the Query: For each employee, retrieve the employee’s name, and the name of his or her immediate supervisor.

A

SELECT E.FNAME, E.LNAME, S.FNAME, S.LNAME

FROM EMPLOYEE AS E, EMPLOYEE AS S

WHERE E.SUPERSSN=S.SSN

68
Q

It is possible to rename any attrivute that appear in the result of a query by adding the qualifier _____ followed by the desired new name.

A

AS

69
Q

The _____ construct can be used to alias both attribute and relation names, and it can appear in both the SELECT and FROM clause of a query.

A

AS

70
Q

What does a missing WHERE-clause indicate?

A

A missing WHERE-clause indicates no condition; hence, all tuples of the relations in the FROM-clause are selected. This is quivalent to a TRUE condition in the WHERE clause.

71
Q

Write the SQL query: Retrieve the SSN values for all employees.

A

SELECT SSN

FROM EMPLOYEE

72
Q

If more than one relations is specified in the FROM-clause and there is no join condition, then the ______ of tuples is selected.

A

CARTESIAN PRODUCT

73
Q

Write the SQL query that retrieves all combinations of an EMPLOYEE SSN and a DEPARTMENT name.

A

SELECT SSN, DNAME

FROM EMPLOYEE, DEPARTMENT

74
Q

To retrieve all the attribute values of the selected tuples, a ____ is used, which stands for all the attributes.

A

*

75
Q

Write the query that retrieves all the attribute values of the EMPLOYEE tuples for employees who work in department number 5.

A

SELECT *

FROM EMPLOYEE

WHERE DNO=5;

76
Q

Write the query that retrieves all the attributes of an EMPLOYEE and all the attributes of the DEPARTMENT he/she works in for every employee of the ‘Research’ department.

A

SELECT *

FROM EMPLOYEE, DEPARTMENT

WHERE DNAME=’Research’ AND DNO=DNUMBER;

77
Q

Write the query that computes the CROSS PRODUCT of the EMPLOYEE and DEPARTMENT relations.

A

SELECT *

FROM EMPLOYEE, DEPARTMENT

78
Q

To eliminate duplicate tuples in a query result, the keyword _____ in the _____ clause is used.

A

DISTINCT; SELECT

79
Q

a query with SELECT ______ eliminates deuplicates, whereas a query with SELECT ______ (which is equivalent to a simple SELECT) does not

A

DISTINCT; ALL

80
Q

Write the query to retrieve the salary of every employee

A

SELECT SALARY

FROM EMPLOYEE

81
Q

Write a query to retrieve every distinct salary value of an employee

A

SELECT DISTINCT SALARY

FROM EMPLOYEE

82
Q

What are the 3 set operations that SQL includes:

A

UNION - union operator

EXCEPT - set difference

INTERSECT - set intersection

The resulting relations of these set operations are sets of typles; duplicate tuples are eliminated from the result.

83
Q

The set operations apply only to _________.

A

union compatible relations

84
Q

union compatible relations

A

the two relations must have the same number of attributes and corresponding attributes must be of compatible data types.

85
Q
A
86
Q

The ____ comparison operator is used to compare partial strings.

A

LIKE

Two reserved characters are used:’%’ replaces and arbitrary number of characters, and ‘_’ replaces a single arbitrary character.

87
Q

Query: Retrieve all employee na,es whose addresss is in Houseton, Texas. here, the value of the ADDRESS attribute must contain the substring ‘Houston, TX’.

A

SELECT FNAME, LNAME

FROM EMPLOYEE

WHERE ADDRESS LIKE‘%Houston, TX%’;

88
Q

Query: Retrieve all employee names who were born during the 1950s.

A

SELECT FNAME, LNAME

FROM EMPLOYEE

WHERE BDATE LIKE‘_ _ _ _ _ _ _ 5 _ ‘;

Here, 5 must be the 9th character of the string (according to our format for date), so the BDATE value is ‘_ _ _ _ _ _ _ 5 _’, with each underscore as a placeholder for a single arbitrary character. (no spaces between).

89
Q

The ____ operator allows use to get around the face that each value is considered atomic and indivisible; hende, in SQL, character string attribute values are not atomic.

A

LIKE

90
Q

The standard arithmetic operators ( __, __, __, __) can be applied to numeric values or attributes with numeric domains.

A

+, -, *, /

91
Q

Query: Show the effect of giving all employee salaries of employees who work on the ‘ProductX’ project a 10% raise.

A

SELECT FNAME, LNAME, 1.1 * SALARY

FROM EMPLOYEE, WORKS_ON, PROJECT

WHERE SSN = ESSN AND PNO = PNUMBER AND PNAME = ‘ProductX’;

92
Q

For string data types, the ____________ can be used in a query to append two string values.

A

concatenate operator (||)

93
Q

Query: Retrieve the names of employees in the form:

first_name/blank_space/last_name

A

SELECT FNAME || ‘ ‘ || LNAME AS NAME

FROM EMPLOYEE

94
Q

A comparison operator that can be used for convenience is

A

BETWEEN

95
Q

Query: Retrieve all employees in department number 5 whose salary is between $30,000 and $40,000.

A

SELECT *

FROM EMPLOYEE

WHERE DNO = 5 AND (SALARY BETWEEN 30000 AND 40000);

96
Q

The _________ clause is used to sort the tuples in a query result based on the values of some attribute(s).

A

ORDER BY

97
Q

Query: Retrieve a list of employees and the projects each works in, ordered by the employee’s department name, and within each department ordered alphabetically by employee last name, first name.

A

SELECT DNAME, LNAME, FNAME, PNAME

FROM DEPARTMENT, EMPLOYEE, WORKS_ON, PROJECT

WHERE DNUMBER=DNO AND SSN=ESSN AND PNO=PNUMBER

ORDER BY DNAME,LNAME,FNAME;

98
Q

The default order is in _______ of values

A

ascending order

99
Q

To specify a descending order we use the keyword ______.

A

DESC

100
Q

The keyword ____ can be used to explicity specify ascending order, even though it is the default.

A

ASC

101
Q

Query: Retrieve a list of employees and the projects each works in, ordered by the empoyee’s department name in descending order, and within each department ordered alphabetically by employee last name, first name.

A

SELECT DNAME, LNAME, FNAME, PNAME

FROM DEPARTMENT, EMPLOYEE, WORKS_ON, PROJECT

WHERE DNUMBER = DNO AND SSN = ESSN AND PNO = PNUMBER

ORDER BY DNAME DESC, LNAME ASC, FNAME ASC;

102
Q

In SQL it is possible to use an explicit (enumerated) set of values in the Where clause of a query. Such a set is enclosed in _______ and the keyword ___ is used.

A

parentheses, IN

103
Q

Query: Retrieve the social security number of employees who work on project number 1,2, or 3.

A

SELECT DISTINCT ESSN

FROM WORKS_ON

WHERE PNO IN (1, 2, 3);

104
Q

_____ in databases are used to represent a missing value.

A

NULLs

105
Q

A NULL for an attribute A in a tuple t can have different meaning. List 3:

A
  1. The value is unknown
  2. The value exists but is not available.
  3. Attribute A does not apply to tuple t.
106
Q

SQL (does/ does not) distinguish between the different meanings of NULL.

A

does not. SQL considers each NULL value is distinct from other NULL values.

107
Q

SQL allows queries that check whether a value is NULL. SQL uses ____ or ____ (instead of using = and <>) to compare NULLs. Since in SQL each NULL value is distinct from other NULL values, equality comparison is not appropriate.

A

IS; IS NOT

108
Q

Query: Retrieve the names of all employees who do not have supervisors.

A

SELECT FNAME, LNAME

FROM EMPLOYEE

WHERE SUPERSSN IS NULL;

109
Q

SQL uses a 3-valued logic with values _____, _____, and ______ instead of the standard 2 valued logic with values TRUE and FALSE. When a NULL is involved in an atomic comparison in SQL, the result is considered to be ______.

A

TRUE (T); FALSE (F); UNKNOWN (U); UNKNOWN (U)

110
Q

Truth table: AND for 3-valued logic.

A
111
Q

Truth table: OR for 3-valued logic.

A
112
Q

Truth table: NOT for 3-valued logic.

A
113
Q

When a join condition is specified, tuples with null values for the join attributes are (included/not included) in the result. This rule does not apploy to OUTER JOINs.

A

not included

114
Q

The concept of a joined table allows users to specify a “joined relation” in the ______ of a query.

A

FROM-clause

115
Q

What are some of the different types of joins a user can specify in the FROM-clause?

A

regular “theta” JOIN, NATURAL JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN, CROSS JOIN

116
Q

Query: Retrieve the first names, last names, and addresses of employees in the ‘Research’ department using joins.

A

SELECT FNAME, LNAME, ADDRESS

FROM (EMPLOYEE JOIN DEPARTMENT ON DNUMBER = DNO)

WHERE DNAME = ‘Research’;

117
Q

In ______ no join condition is specified. The implicit equijoin condition involves each pair of attributes with the same names in both relations.

A

natural join

118
Q

Query: Retrieve the employees’ first names, last names, and addresses who work in the Research department using natural join.

A

SELECT FNAME, LNAME, ADDRESS

FROM (EMPLOYEE NATURAL JOIN DEPARTMENT AS DEPT(DNAME, DNO, MSSN, MSDATE))

WHERE DNAME=’Research’;

119
Q

Query: Retrieve the names of employees and their supervisors including the employees who have no supervisor using left outer join.

A

SELECT E.FNAME, E.LNAME, S.FNAME, S.LNAME

FROM (EMPLOYEE E LEFT OUTER JOIN EMPLOYEE S ON E.SUPERSSN=S.SSN);

120
Q

Query: Use nested join specifications to retrieve the addresses of the managers that manage projects in ‘Stafford’.

A

SELECT ADDRESS

FROM ((PROJECT JOIN DEPARTMENT ON DNUM=DNUMBER) JOIN EMPLOYEE ON MGRSSN=SSN)

WHERE PLOCATION=’Stafford’;

121
Q

A complete SELECT query, called a _________ can be specified within the WHERE-clause of another query, called the ______.

A

nested query; outer query

122
Q

Query: Retreive the name and address of all employees who work for the ‘Research’ department using nested queries.

A

SELECT FNAME, LNAME, ADDRESS

FROM EMPLOYEE

WHERE DNO IN (

SELECT DNUMBER

FROM DEPARTMENT

WHERE DNAME=’Research’);

The nested query selects the number of the ‘Research’ department.

The outer query selects an EMPLOYEE typle if its DNO value is in the result of the nested query.

The comparison operator IN compares a value v with a set (or multi-set) of values V, and evaluates to TRUE if v is one of the elements in V.

123
Q

Query: Make a list of all project numbers for projects that involve an employee whose last name is ‘Smith’ as a worker or as a manager of the department that controls the project.

A

SELECT DISTINCT PNUMBER

FROM PROJECT

WHERE PNUMBER IN

(SELECT PNUMBER

FROM PROJECT, DEPARTMENT, EMPLOYEE

WHERE DNUM=DNUMBER AND MGRSSN=SSN AND‘Smith’)

OR PNUMBER IN

(SELECT PNO

FROM WORKS_ON, EMPLOYEE

WHERE ESSN=SSN AND LNAME=’Smith’);

124
Q

To compare a tuple of values using IN comparison, place the values in _____.

A

parentheses

125
Q

Query: Select the social security number of all employees who work the same (project, hours) combination on a project that the employee whose SSN is ‘123456789’ works on using tuple comparison and IN.

A

SELECT DISTINCT ESSN

FROM WORKS_ON

WHERE (PNO, HOURS) IN

(SELECT PNO, HOURS

FROM WORKS_ON

WHERE ESSN = ‘123456789’);

126
Q

Query: retrieve the names of the employees whose salary is greater than the salary of all the employees in department number 5.

A

SELECT LNAME, FNAME

FROM EMPLOYEE

WHERE SALARY > ALL (SELECT SALARY

FROM EMPLOYEE

WHERE DNO=5);

127
Q

Abiguity can arist among attribute names if the same attribute exists in relations in the FROM clauses of both the outer query and a nested query. What are the two rules we use to deal with this ambiguity?

A
  1. A reference to an unqualified attribute refers to the relation declared in the innermost nested query.
  2. To refer to an attribute of a relation specified in an outer query, we can specify and refer to an alias for that relation.
128
Q

Attributes SALARY and DNO in the nested query refer to which relation EMPLOYEE ?

A

Attributes SALARY and DNO in the nested query refer to the EMPLOYEE relation declared in the nested query.

129
Q

If a condition in the WHERE-clause of a nested query references an attribute of a relation declare in the outer query, the two queries are said to be ______.

A

correlated

130
Q

The result of a correlated ______ is different for each tuple (of combination of tuples) of the relation(s) of the _____.

A

nested query; outer query

131
Q

We can understand a correlated query by considering that the nested query is evalued ____ for each tuple (or combination of tuples) of the out query.

A

once

132
Q

Query: Retrieve the name of each employee who has a dependent with the same first name and sex as the employee.

A
133
Q

In general, can a query with nested SELECT-FROM-WHERE blocks that uses the IN comparison operator be expressed using a single query block?

A

Yes. Example: Retrieve the name of each employee who has a dependent with the same first name and sex as the employee.

134
Q

The _____ function in SQL is used to check whether the result of a correlated nested query is empty (contains no tuples) or not.

A

EXISTS

135
Q

Query: Retrieve the name of each employee who has a dependent with the same first name and sex as the employee using EXISTS..

A
136
Q

The function ________ can also be used. EXISTS(Q) returns ___ if there is at least one tuple in the result of Q, and ____ otherwise.

______ returns TRUE if there are no tuples in the result of Q, and FALSE otherwise.

A

NOT EXISTS; TRUE; FALSE; NOT EXISTS(Q);

137
Q

Query: Retrieve the names of employees who have no dependents using NOT EXISTS.

A

SELECT FNAME, LNAME

FROM EMPLOYEE

WHERE NOT EXISTS (SELECT *

FROM DEPENDENT

WHERE SSN=ESSN);

138
Q

Query: List the names of managers who have at least one dependent using EXISTS.

A
139
Q

Query: Retrieve the names of each employee who works on all the projects using NOT EXISTS and EXCEPT.

A
140
Q

The SQL function _______ returns TRUE is there are no duplicates in the result of a query Q; otherwise it returns FALSE.

A

UNIQUE(Q)

141
Q
A