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'));
Comments
Leave a comment