i want to store a weekdays in my database like (Sunday ,...,Friday) what datatype should i use? thank you :)
CREATE TABLE Operations(
operation_id int not null AUTO_INCREMENT,
PRIMARY KEY(operation_id),
openingtime time,
closingTime time,
operationDay ?????
restaurant_id int,
FOREIGN KEY(restaurant_id)
REFERENCES restaurant(restaurant_id)
ON UPDATE CASCADE
);
example
id = 1
openingtime = 7:00am
closingTime = 10:00pm
operationDay = monday
restaurant_id = 2
the purpose of storing days and time, i want to display if the restaurant is open or close real-time.
How about a column with the ENUM
type? http://dev.mysql.com/doc/refman/5.7/en/enum.html
From the documentation:
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time. It has these advantages:
Compact data storage in situations where a column has a limited set of possible values. The strings you specify as input values are automatically encoded as numbers. See Section 12.8, “Data Type Storage Requirements” for the storage requirements for ENUM types.
Readable queries and output. The numbers are translated back to the corresponding strings in query results.
So your table definition would look like this:
CREATE TABLE Operations(
...
operationDay ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'),
...
);