Answer to Question #228427 in Databases | SQL | Oracle | MS Access for Nanthu

Question #228427
Write the SQL commands that represent the following: Suppose you have created a table called Player. And the DBA asked you to edit the table and restrict the values of a field called "wins the Ballon Dor" to "Yes" or "No". Which means the data to be inserted in this field must be yes or no only.
1
Expert's answer
2021-08-23T01:19:27-0400

To restrict the value of a field in SQL, a CHECK CONSTRAINT can be used. This check constraint will check the values in the field for certain values only, and putting other values won't work. The name of the constraint can be anything meaningful. Also, to use the field "wins the Ballon Dor", as it's a multi word field, backquotes (`) can be used for specifying the field.

Assuming table Player is already created, here is the SQL command to add the constraint -

ALTER TABLE Player 
ADD CONSTRAINT CHECK_WINS_IN_BALLON_DOR 
CHECK (`wins the Ballon Dor` IN ('Yes', 'No'));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS