I am afraid that this question might be a little too broad, but I have little-to-none knowledge when it comes to database design, so I will explain what I have so far before I get to the question.
I have an excel file, which I exported into a csv file, which has the following (simplified) layout:
Region, License Number in 1st Year, License Number in 2nd Year, License Number in 3rd Year...
The idea is that the licenses are incremented and at the end of every year, I have a record of what is the highest license at the time for each region. Because there are almost as many regions as there are years, it makes sense the previous layout for an excel file because we have the data displayed in what is close to be a square, but for the database I believe that it could be easier to deal with it if I reduce the number of columns and I would have this:
Region, Year, License Number
Assuming that this is right (again, I am clueless when it comes to database design) my question is the following: how can I possibly convert all the data to the suggested format without having to manually create the (many) entries for each region and copy all the licenses into the corresponding years?
The goal is to be able to tell what year a license was issued by simply looking at the license number
Looks like you’re on the right track. You’ll want a primary key on {region, year}.
If you’re relatively new to databases, the procedure below will be the easiest both for you to understand and for you to get right the first try.
One problem is that you don’t appear to be storing the years. If 1st year means the same year for every value in that Excel column–that is, 1st year doesn’t mean 2011 for one row, and 1999 for another–then you might be able to massage the data into shape easily just using a second worksheet.
another worksheet.
two, copy the number 2005 all the way down the second column, and
you’re done. (Done with 1st year, that is.)
If you think you’re comfortable running queries, you can try this procedure.
Create a table for your data. I’m guessing at the data types.
create table your_table_name (
region varchar(35) not null,
year integer not null check (year >= 1955),
license_num integer not null check (license_num >= 0)
);
Export your spreadsheet to CSV file. Consider changing the column
names to the actual years.
Insert data into your_table_name.
Note carefully that you’ll need to adjust the literal year and the name of the column for that year each time you run the query.