Andrew Keller
Andrew Keller

Reputation: 3239

SQL Server day datatype?

I am creating a table for an application that handles scheduling and deals with recurring events. I need to indicate which days and times an event may recur on (eg. every Monday and Wednesday at 1pm). Is there a datatype that can handle only days of the week without inputting specific dates, or will I need to create another table containing days of the week and reference these with a FK? This is obviously undesirable because it will make handling events that start before midnight and end after midnight more complex.

Upvotes: 3

Views: 6006

Answers (2)

Branko Dimitrijevic
Branko Dimitrijevic

Reputation: 52117

Looks like you need something similar to this:

CREATE TABLE T (
    DAY_OF_WEEK TINYINT CHECK (DAY_OF_WEEK BETWEEN 1 AND 7)
    -- Other fields and constraints...
)

Upvotes: 1

Mitch Wheat
Mitch Wheat

Reputation: 300559

Use a smallint for the Day of Week.

If you are using SQL Server 2008, there is a new time datatype for the time of day column, otherwise you will still need to use a datetime datatype.

Upvotes: 3

Related Questions