Does it make sense to define a new "Data type"? Is there a way to do so? I'm basically new to SQL, and I was making my own project when this question came to my mind.
I'm making a database that has an entity where an attribute would be a &quot;number&quot; and a &quot;year&quot;.
In many programming languages one would create a new object or data type that takes both the number and the year. (say a tuple with INT, YEAR)
I wanted to know if this makes sense in SQL or I should just go with an INT and YEAR attribute.
To put more details into the project, I'm creating a DB for my mom who runs a business that goes with &quot;campaings&quot; (the INT value) directly associated with the &quot;Year&quot;, so one would put the campaign 09 for year 2020, and so on.
I wanted to create a new Data Type for the attribute so then I don't have multiple &quot;campaign 09&quot; with different years.
I hope my question is clear, thanks!
EDIT: Read the comments for the answer.
This isn't something that requires a custom data type to solve.
If the requirement is Campaign 09 can only be associated with one year, then Year is simply an attribute for Campaign (although I'd argue perhaps StartDt or something similar, from which year can be derived might be more appropriate).
To illustrate:
CREATE TABLE Campaign
(
  CampaignNbr  INT   NOT NULL
 ,StartDt      DATE  NOT NULL
 /* Everything else */
 ,CONSTRAINT PK_Campaign PRIMARY KEY (CampaignNbr)
)