37,790 views
111 111 votes

Given the following statements: 

S1: A foreign key declaration can always be replaced by an equivalent check  assertion in SQL. 

S2: Given the table $R(a,b,c)$ where $a$ and $b$ together form the primary key, the following is a valid table definition. 

CREATE TABLE S ( 
     a INTEGER, 
     d INTEGER, 
     e INTEGER, 
     PRIMARY KEY (d), 
     FOREIGN KEY (a) references R)

Which one of the following statements is CORRECT?

  1. S1 is TRUE and S2 is FALSE
  2. Both S1 and S2 are TRUE
  3. S1 is FALSE and S2 is TRUE
  4. Both S1 and S2 are FALSE

5 Answers

Best answer
143 143 votes

(D) Both are false.

S1: Foreign key constraint means a lot of constraints it has to be a primary key(which in turn has few constraints).

Alternate reason: Using a check condition we can have the same effect as Foreign key while adding elements to the child table. But when we delete an element from the parent table the referential integrity constraint is no longer valid. So, a check constraint cannot replace a foreign key.
So, we cannot replace it with a single check.

S2:  if $a$ and $b$ form a primary key in $R$, $a$ alone cannot form a foreign key. i.e. $R(\underline{a, b}, c)$ and $S(a, d, e)$, $a$ of $S$ references to $a$ of $R$, but $a$ of $R$ is not candidate key, instead a prime attribute since $a, b$ combined is a key.

Foreign key definition: it should be a candidate key in some other table(in our case it is only a prime attribute).

edited by
1 flag:
✌ Edit necessary (Anklesh Pathak13 “Foreign key itself needs not to be a candidate key ...the reference key that a foreign key is referring to ...must be a candidate key”)
35 35 votes

I think this is a more reasonable solution

Explanation:

    S1: A foreign key declaration can always
        be replaced by an equivalent check
        assertion in SQL. 

False:
Check assertions are not sufficient to replace foreign key. Foreign key declaration may have cascade delete which is not possible by just check insertion.

    S2: Given the table R(a,b,c) where a and
        b together form the primary key, the
        following is a valid table definition.
        CREATE TABLE S (
            a INTEGER,
            d INTEGER,
            e INTEGER,
            PRIMARY KEY (d),
            FOREIGN KEY (a) references R) 

False:
Foreign key in one table should uniquely identifies a row of other table. In above table definition, table S has a foreign key that refers to field ‘a’ of R. The field ‘a’ in table S doesn’t uniquely identify a row in table R.

Take an example 

R                                                           

A B C
1 1 L
1 2 Z
2 1 K

S

A D E
1 2 H
1 4 G
1 3 T

Now, here in S, attribute A alone cannot be used to uniquely identify a particular row in R. Hence S2 is false.

Hence (D) is the answer.

3 3 votes
    S1: A foreign key declaration can always
        be replaced by an equivalent check
        assertion in SQL. 

False:
Check assertions are not sufficient to replace foreign key. Foreign key declaration may have cascade delete which is not possible by just check insertion.

    S2: Given the table R(a,b,c) where a and
        b together form the primary key, the
        following is a valid table definition.
        CREATE TABLE S (
            a INTEGER,
            d INTEGER,
            e INTEGER,
            PRIMARY KEY (d),
            FOREIGN KEY (a) references R) 

False:
Foreign key in one table should uniquely identifies a row of other table. In above table definition, table S has a foreign key that refers to field ‘a’ of R. The field ‘a’ in table S doesn’t uniquely identify a row in table R.

0 0 votes
A SQL check constraint is a rule that limits the values that can be inserted or updated in a column (or set of columns) of a table. It enforces data integrity by ensuring that only values satisfying a specified condition or expression are allowed. If an attempt is made to enter data that violates the constraint, the database rejects the operation.

Check constraints can be defined at the column level or table level. For example, you could use a check constraint to ensure that an "Age" column must be greater than or equal to 18, or to ensure that a "Salary" column's value must always be above a certain amou

Cannot reference values in other tables; checks only conditions within the current row or tablent.
Answer:
Position:
Show:

Related questions

78 78 votes
11 answers 11 answers
33.1k
33.1k views
go_editor asked Sep 28, 2014
33,125 views
Consider a $6$-stage instruction pipeline, where all stages are perfectly balanced. Assume that there is no cycle-time overhead of pipelining. When an application is exec...
68 68 votes
6 answers 6 answers
22.9k
22.9k views
go_editor asked Sep 28, 2014
22,905 views
Given the following schema: employees(emp-id, first-name, last-name, hire-date, dept-id, salary) departments(dept-id, dept-name, manager-id, location-id)You wan...
63 63 votes
5 answers 5 answers
21.8k
21.8k views
go_editor asked Sep 26, 2014
21,800 views
Given the following two statements: S1: Every table with two single-valued attributes is in $\text{1NF, 2NF, 3NF}$ and $\text{BCNF}.$ S2: $AB \to C, D \to E, E \to C$ is ...
36 36 votes
4 answers 4 answers
14.7k
14.7k views
go_editor asked Sep 26, 2014
14,697 views
Consider the following four schedules due to three transactions (indicated by the subscript) using read and write on a data item x, denoted by $r(x)$ and $w(x)$ respectiv...