0

i use mysql workbench, in my DB i have a table called invoice with tho fields number and date. i want to do something like this:

primary key (number, date.year). or unique(number, date.year)

i tried both but i did not succeed, why? is it not allowed? someboby can help me?

  • 1
    You'll want a `Year` field, or just the full date in the key. It seems odd that just part of a date field would be key, this implies only one date per year. – Hart CO Mar 07 '16 at 20:12
  • i can't do this primary key (date, number) or primary key (year) the real primary key is composed by the year and the number of the invoice because i can havo only one invoice number 'X' in a year, but i can have invoice number 1 in year 2016 and invoice number 1 in year 2017. – davide tombari Mar 07 '16 at 20:28
  • i can declare three flied int year int month and int day in place of the date field, and so i can put year and number as composite primary key but i don't want do this because at runtime i have to do a lot of convertions. – davide tombari Mar 07 '16 at 20:36

0 Answers0