Reputation: 14
How create column in table with constraints to be its input only from group of CHARS I did like that but it
CREATE TABLE IF NOT EXISTS `UNIVERSITY`.`GRADE REPORT`
(`Student_number` int,
`Section_id` int,
`Grade` char IN ('A', 'B', 'C','D', 'E', 'F');
Upvotes: 0
Views: 59
Reputation: 9018
To create a column with specific datas (char, int .etc) you can use ENUM
: https://dev.mysql.com/doc/refman/8.0/en/enum.html.
I suggest do not use spaces between table name.
Try:
CREATE TABLE IF NOT EXISTS `UNIVERSITY`.`GRADE_REPORT`(
`Student_number` int,
`Section_id` int,
`Grade` ENUM('A', 'B', 'C', 'D', 'E','F')
);
You can add default value too:
CREATE TABLE IF NOT EXISTS `UNIVERSITY`.`GRADE_REPORT`(
`Student_number` int,
`Section_id` int,
`Grade` ENUM('A', 'B', 'C', 'D', 'E','F') DEFAULT 'A'
);
Working Demo: https://www.db-fiddle.com/f/vwi9bkdUVPoZeURdNAEoDX/9
Not Working Demo: https://www.db-fiddle.com/f/vwi9bkdUVPoZeURdNAEoDX/10
Upvotes: 1