129k views
1 vote
Suppose two relations R(A:int, B:string) and S(C:int, D:string). Which of the followings is valid in SQL ?

Select one:
a. ALTER TABLE R ADD CONSTRAINT RCHK CHECK (A, B IN (SELECT * FROM S));
b. ALTER TABLE R ADD CONSTRAINT RCHK CHECK (A IN (SELECT * FROM S));
c. ALTER TABLE R ADD CONSTRAINT RCHK CHECK (A IN (1,2,3,4,5));
d. ALTER TABLE R ADD CONSTRAINT RCHK CHECK (A IN (SELECT C FROM S));

User Colin Wang
by
8.5k points

1 Answer

3 votes

Final answer:

The correct SQL statement for adding a CHECK constraint is: ALTER TABLE R ADD CONSTRAINT RCHK CHECK (A IN (SELECT C FROM S)); This ensures that values in column A of table R are limited to those in column C of table S.

Step-by-step explanation:

The question is related to SQL and how to correctly add a CHECK constraint to a table with an ALTER TABLE statement. The correct option among the given choices is:

  • d. ALTER TABLE R ADD CONSTRAINT RCHK CHECK (A IN (SELECT C FROM S));

This statement is valid because it sets a constraint that ensures the values in column A of table R are limited to those values that also appear in column C of table S. The subquery (SELECT C FROM S) returns the set of values from column C of table S, which are then used as a reference for the values allowed in column A of table R.

User Nathanjessen
by
7.7k points