what should i do if i want to make a double that doesn’t go higher than 5?

In MySQL 8.0, you can use a check constraint:

create table restaurant(
    restaurantname varchar(17),
    rating decimal(5, 4) check(rating between 0 and 5)

You probably don’t need double precision to store a rating. I changed the datatype to a decimal, with 4 decimal positions.

I also assumed that you want a value between 0 and 5 inclusive. If you wanted to exclude the upper bound, then:

    rating decimal(5, 4) check(rating >= 0 and rating < 5)

In earlier versions, you would typically need to implement the logic with a trigger.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top