Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6708243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:44:08+00:00 2026-05-26T07:44:08+00:00

i have to store year and month in my table with two other columns

  • 0

i have to store year and month in my table with two other columns next month theme and theme details what data type should i use

should i use smalldatetime and store them by making a date like 09/01/2011 ?

should i use two columns of varchar or int to store separate year and
month like 2011 09 ?

should i use one column varchar in which store them with concatenating them
like 201109 ?

EDITED

one thing i also want to add that i have to use these columns in searching also so i have to use them in where clause so in answer this thing is also important

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:44:09+00:00Added an answer on May 26, 2026 at 7:44 am

    Normally, I would advise to use the date date types no matter what your restrictions, since it allows you to do date manipulations and comparisons. You could then use triggers to restrict dates to the first of the month. You’d need triggers to ensure that you couldn’t get two rows for a single month/year combo.

    Actually, as Damian_The_Unbeliever rightly points out in a comment, you don’t need triggers if your intent is to only allow users to attempt insertion of dates where the day of the month is 1. In that case, constraints will probably be enough. It’s only the case where you want to allow users to attempt to insert any date but actually force it to become the first day of that month, that triggers would be required.

    However, in this case, I’d be quite happy with a two-column year/month setup, based on your use case.

    By using two integer-type columns, you don’t need to worry about triggers, and you don’t seem to have a need for massive processing of the table contents, based on your column specifications.

    I wouldn’t store them as a single integer-type column if you ever foresee the need to process data for a given year (independent of the month). Having the year separate will allow a distinct index which will probably be faster than getting a range of YYYYMM values.

    Seriously, choose the one that you think will be easiest to code up (and meets the functional requirements). Then if, and only if, you discover a performance problem, look into a schema re-org. Databases are not set-and-forget things, you should be constantly monitoring them for problems and, if necessary, changing things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to store only the month and the year in oracle data type.
Hi I have the next store procedure `USE [BD_SSEGUA] GO / * Object: StoredProcedure
I have a database which needs to store year ranges (such as lifespan) which
I have a database table that stores document information (DocID, Name, Type, Owner, etc).
I have a table called Basic , start_time is one field with type :VARCHAR(5),
I have a field on my table which is called X, and I store
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
As I am working on Employee Management system, I have two table (for example)
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have a MySQL table (A) which has, amongst others, three columns named day,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.