Mysql table structure design for economic data - mysql

Dear all Mysql experts
I am very new for Mysql, please providing me some guides here. I have data as shown in picture above, and I am trying to design table structure of Mysql to store those data and the data will be added over the years, which i dont want to record same indicator multiple times. at the moment i was thinking about split the data into 3 tables: indicator table to hole indicator name, data value table to hold data value and year and the geography table to hold provinces but i am not quite sure if that approach is right please giving me some shade of light. Thank you very much.

Because its a simple question that deserves a simple answer, here is a suggestion. As per the comments, the sample data you have given is ambiguous, but with assumptions this is it.
From your data, it looks like Indicator, Category and Source are all attributes of the same entity. It also looks like there are an arbitrary number of provinces. If so then you are likely to have three tables
Indicator(IndicatorID,IndicatorText,Category,Source)
Province(ProvinceID,ProvinceName)
YearValue(IndicatorID,ProvinceID,Year,Value)
You would probably not store the national value, just add up the provinces.

Related

Need help starting simple MySQL database using data from Excel

I'm and intern and I've been tasked with something I'm pretty unfamiliar with. My manager has requested I create a simple MySQL database using data from an Excel file(s) and I have no idea where to start. I would normally ask someone here for help but everyone seems to be really busy. Basically, the purpose of the database is to see what different object-groups relate to one another so as to keep things standardized. Trying not to go into detail about things not really relevant.
I was asked to first design a schema for the database and then I would get an update on how to implement it. Would I just start by writing queries to create tables? I'm assuming I would need to convert the Excel files to .csv, how do I read this data and send it to the correct table based on Object Type (an attribute of each object, represented in a column)?
I don't want to ask too much right now, but if someone could help me understand what I need to do to get started I would really appreciate it.
Look at the column headers in your spread sheet.
Decide which columns relate to Objects and which columns relate to Groups
The columns that relate to just Objects will become your field names for the Object table. Give this table an ID field so you can uniquely identify each Object.
The columns that relate to the Groups will become field names for a Group table. Give this table an ID field so you can uniquely identify each Group.
Think about if an Object can be in more than one Group - if so you will probably need an Object-Group table. This table would most likely contain an ObjectID and a GroupID.

BMD Database Schema

Okay, so this problem is stumping me somewhat and I would appreciate some help from someone regarding normalisation (and the end goal of having the ability to search all records at once) if at all possible.
I'm trying to construct a database schema that holds birth, baptism, marriage, death & burial records, as entered from original 1800's documents.
Each record type has unique information that needs to be recorded so as it stands I have a table for each type. Please have a look at the following draft schema;
The obvious data to normalise in the three tables I've used in the example (tbBaptism, tbMarriage, tbBurial) are the location, the church and the source as I have done in that draft schema. Ideally the person would also be normalised into their own table, but with the data I am dealing with, it is not possible to identify all individuals.
Now the problem (if indeed it is actually a problem?) is I feel like there must be a better way of storing the data in the tables tbBaptism, tbMarriage, tbBurial ... perhaps combining them into one table? ... possibly an event table which has the common fields such as the event date, location, church, etc. but how would I store the unique fields such as marriage witnesses for example?
Am I trying to over simplify things and is the current draft schema is the way to go?
I'm looking for ideas/suggestions that will make my life easier in the long run!!

Best way to store trivia alternatives?

I'm creating an application that asks the user a question and demands an answer in the form of a country.
For example: Where is the Eifell Tower located?
The user is presented with a number of alternatives, lets say 10 different countries.
The problem arrises when I want to store every answer to a mySQL-database. I have a table with all the countries, and need to store which of them were included in the question. However, doing it this way would create, in this case, 10 database rows for a single answered question. I've been looking into storing the included countries as a bit mask, but a single bit mask wouldn't be enough with over 150 possible countries.
Any help on what would be a good way to store the data is much appreciated!
Thanks!
I'd just store The relation in a table like you are suggesting. I.e, three tables where the first contains questions (Id, question_text, ..), the second table contains all the countries (Id, name, ..) and the third table contains the relation that says what country is an option in which question (question_id, country_id). Like you say this gives ten rows in the relationship table for a single question, but are you really facing a storage space or performance problem here?
If you have 10k such questions, it is still just 100k rows and less than a megabyte of data. The questions themselves will have a lot more data than that, so the relation between question and country shouldn't be an issue as far as I can see.

More rows or more tables in a db design?

I'm pretty sure I already know the answer, but would like some confirmation...
We received 220 text files of providers. Each file is a different category of provider. In total there are 3.2 million records.
My inclination is to create a category table and a provider table that links to category by an ID, then index any other columns that may be searched on like state, or even last name.
The other option is to have one table per category, but I think other than the smaller row size there are a lot of disadvantages to this approach.
It's a PHP/MySQL implementation.
Anyone think the separate table option is better for any reason?
Thanks,
D.
Go with two table approach -- categories and providers.
This will enable you to
easily adding new categories
easily reverse search Categories based on a column such as state of provider.
It make sense from data-structure point of view as well. One type of data in one table.
I agree with your original thought, and with Nishant's answer. In addition to his points, it also normalizes the data, and allows easy updates if a category changes names for some reason.

A Beginner Question on database design

this is a follow-up question on my previous one.We junior year students are doing website development for the univeristy as volunteering work.We are using PHP+MySQL technique.
Now I am mainly responsible for the database development using MySQL,but I am a MySQL designer.I am now asking for some hints on writing my first table,to get my hands on it,then I could work well with other tables.
The quesiton is like this,the first thing our website is going to do is to present a Survey to the user to collect their preference on when they want to use the bus service.
and this is where I am going to start my database development.
The User Requirement Document specifies that for the survey,there should be
Customer side:
Survery will be available to customers,with a set of predefined questions and answers and should be easy to fill out
Business side:
Survery info. will be stored,outputed and displayable for analysis.
It doesnt sound too much work,and I dont need to care about any PHP thing,but I am just confused on :should I just creat a single table called " Survery",or two tables "Survey_business" and "Survey_Customer",and how can the database store the info.?
I would be grateful if you guys could give me some help so I can work along,because the first step is always the hardest and most important.
Thanks.
I would use multiple tables. One for the surveys themselves, and another for the questions. Maybe one more for the answer options, if you want to go with multiple-choice questions. Another table for the answers with a record per question per answerer. The complexity escalates as you consider multiple types of answers (choice, fill-in-the-blank single-line, free-form multiline, etc.) and display options (radio button, dropdown list, textbox, yada yada), but for a simple multiple-choice example with a single rendering type, this would work, I think.
Something like:
-- Survey info such as title, publish dates, etc.
create table Surveys
(
survey_id number,
survey_title varchar2(200)
)
-- one record per question, associated with the parent survey
create table Questions
(
question_id number,
survey_id number,
question varchar2(200)
)
-- one record per multiple-choice option in a question
create table Choices
(
choice_id number,
question_id number,
choice varchar2(200)
)
-- one record per question per answerer to keep track of who
-- answered each question
create table Answers
(
answer_id number,
answerer_id number,
choice_id number
)
Then use application code to:
Insert new surveys and questions.
Populate answers as people take the surveys.
Report on the results after the survey is in progress.
You, as the database developer, could work with the web app developer to design the queries that would both populate and retrieve the appropriate data for each task.
only 1 table, you'll change only the way you use the table for each ocasion
customers side insert data into the table
business side read the data and results from the same table
Survey.Customer sounds like a storage function, while Survey.Business sounds like a retrieval function.
The only tables you need are for storage. The retrieval operations will take place using queries and reports of the existing storage tables, so you don't need additional tables for those.
Use a single table only. If you were to use two tables, then anytime you make a change you would in effect have to do everything twice. That's a big pain for maintenance for you and anyone else who comes in to do it in the future.
most of the advice/answers so far are applicable but make certain (unstated!) assumptions about your domain
try to make a logical model of the entities and attributes that are required to capture the requirements, examine the relationships, consider how the data will be used on both sides of the process, and then design the tables. Talk to the users, talk to the people that will be running the reports, talk to whoever is designing the user interface (screens and reports) to get the complete picture.
pay close attention the the reporting requirements, as they often imply additional attributes and entities not extant in the data-entry schema
i think 2 tables needed:
a survey table for storing questions and choices for answer. each survey will be stored in one row with a unique survey id
other table is for storing answers. i think its better to store each customers answer in one row with a survey id and a customer id if necessary.
then you can compute results and store them in a surveyResults view.
Is the data you're presenting as the questions and answers going to be dynamic? Is this a long-term project that's going to have questions swapped in and out? If so, you'll probably want to have the questions and answers in your database as well.
The way I'd do it would be to define your entities and figure out how to design your tables so relationships are straightforward. Sounds to me like you have three entities:
Question
Answer
Completed Survey
Just a sample elaboration of what Steven and Chris has mentioned above.
There are gonna be multiple tables, if there are gonna be multiple surveys, and each survey has a different set of questions, and if same user can take multiple surveys.
Customer Table with CustID as the primary key
Questions Table with a Question ID as the primary key. If a question cannot belong to more than one survey (a N:1 relationship), then can also have Survey ID (of table Survey table mentioned in point 3) as one of the values in the table.
But if a Survey to Question relationship is N:M, then
(SurveryID, QuestionID) would become a composite key for the SurveyTable, else it would just have the SurveyID with the high level details of the survey like description.
UserSurvey table which would contain (USerID, SurveryID, QuestionID, AnswerGiven)
[Note: if same user can take the same survey again and again, either the old survey has to be updated or the repeat attempts have to stored as another rows with some serial number)