Relational Database Design (Access) - database

I am attempting to design a DB that houses peoples time that is assigned to a project.
So for example, Bill is assigned to 20 hours on project A, and 20 hours on project B for weeks 50-52 of this year. For weeks 1-9 of next year he is assigned to project C for 40 hours a week.
How would you structure your database so that it could house all of this information for n number of people and projects?

Without knowing more details, it looks like you need three tables:
Person
Project
Person2Project (the join table)
You would enter your employee information in the Person table, Project Information in the Project table, and use the third table to join a person to a project using a primary key/foreign key. The information regarding weeks and hours would be included in the third table.

Related

Keep getting many-to-many relationships and I don't understand why

I have three tables:
Student - a table with student information including program, year entered, etc. Each student has a unique ID.
Fellowship packages - each academic year has a selection of fellowships available, though some packages can occur in multiple years. Each package has amounts associated for each semester during the academic year.
Awards - I want a table which has entries for: student, academic year of award, package, amounts associated with each package.
I should say, I also will need a field in "Awards" that denotes the funding source for each semester in each award.
The "Awards" table is linked to the "Student" table by the students ID#. It's linked to the "Package" by Academic Year. My problem is that I keep getting many-to-many relationships between "Awards" and "Packages", even if I create a separate table with just a list of the years and go through that.

More Rows vs More Tables

I have recently started designing database for one of my project. I am confused on one simple question "More Rows vs More Tables". I am not experienced enough to answer this question. Any help on this will be appreciated. Here is the scenario:
Scenario
I Have a Company. Company will have many Users, Vehicles.
More Rows:
Should I have 1 table for user and vehicle with reference to COMPANY_ID. Obviously over time it will have a lot of records. I have to use GUID as ID because of the requirement. So if it has too many records, I think it will effect the searching operation as well.
More Tables:
Should I have 2 tables created every time I add a new company with company prefix e.g. I add a new company "Tesla", table names will be like TESLA_USER, TESLA_VEHICLES. Obviously over time number of tables will increase a lot.
My concern is which is more efficient way? More Rows or More Tables?
Thank you
Cheers
D
You can create a table for the Companies, a table for users and a table for vehicles in which you put all your data. Then you add two joining tables who only stores the links between companies and users and companies and vehicles.
Example

Can a join table be combined with another table?

The first image below is my database schema for a project that will use psql, ruby and active record.
While writing my schema, things got a bit complex. My "special_days" table ended up becoming a join table for "days_of_week" and "organizations". I'm assuming that this is not best practice and will end up causing me trouble.
In the second schema below, I made a separate join table for "days of week" and "organizations". My special_days table still needs to be associated with a day_of_week and an organization, so I think I have to keep the joining information in the special_days table. Is there a better way to do this? It seems that my second attempt is too repetitive.
These are my relationships:
days of week & organizations | many to many
city & organizations | one to many
organization & special days | one to many
day of week & special days | one to many
Some more information about the requirements might be useful. Are you required to do something like define which days are holidays, which days are paydays, etc. (e.g. many organizations would define Sat and Sun as non-work days and many U.S. organization would define July 4 as a non-work day)? I'm not sure what days_of_the week represents. Is this a table with 7 records in it (M,T,W,Th,F,S,Sun)? If I'm guessing correctly at the requirements it might be better to do something like have a table called special_day that has a date column and a recurrence column (e.g. weekly, monthly, yearly, etc.). You could then have a organization_special_day table that is a many-to-many join table on organization and special_day.

Record clustering based on Place and Time in SQL

I would like to know if any of you guys have written a query for record clustering based on overlapping time intervals AND locations.
Data in my application is represented as individual events of a person being at any given location from start time to end time. Location is defined as latitude and longitude. During a day one person will have multiple different locations and start and end times. I need to get groups of persons who were at the same location and at the same time. One person will most likely be in several groups during a day.
Example:
Person A can be with Person B at the office from 10 AM to 11 AM.
Then Person A leaves the office for gym.
There he is with Person C from 12 noon to 1PM.
At 12:30 Person C leaves gym for the office.
At 1:30PM I have Person B and C at the office.
Persons B and C leave the office at 5PM.
In this example I have
Cluster 1 (Person A and B at the office) from 10AM to 11AM,
Cluster 2 (Person A and C at the gym) from 12 noon to 1PM, and
Cluster 3 (Person B and C at the office) from 1:30PM to 5PM.
The Location of each individual person will not match exactly to another person's location. I'm using SQL geography point type with the STBuffer of proximity threshold and check for STIntersects. I'm also joining the table on itself to check time overlaps. But i'm experiencing some weird behaviors when Person A gets clustered on itself without other person ever joining him.
I'm wondering if there's a design pattern for handling situations like this. Ideally i would have the recordset grouped on "Overlapping Time Period" and "Centroid of an arbitrary geometry" but can't figure out how to get the overlapping time period and the arbitrary geometry.
Any ideas are welcome and highly appreciated.
P.S. writing a windows application is not an option unless it's the only way.
EDIT: Failed to mention that locations of clustering is never known in advance. There can be indefinite number of locations where two or more of my customers may cluster. I don't know if clustering will happen in the office, gym, some park or at a bus station. Clustering location (i think ) will be the Centroid of a polygon represented by all congregated people's Latitudes and Longitudes.
Would the code be something like
select a.person,a.eventtime,a.eventplace,
b.person,b.eventtime,b.eventplace
from people a
join people b on a.eventtime between dateadd(hh,-2,b.eventime) and dateadd(hh,2,b.eventime)
and yourdistancefunction(a.eventplace ,b.eventplace) < 5 -- don't know what you are measuring
and a.person<>b.person
I solved the puzzle by first getting the entire dataset for the given time period. Looping through the recordset and generating STUnion shapes for all overlapping locations. Then joining the generated temporary table on the initial datased and getting only the records that intersected with STUnion shapes AND with each other in time.
Used three temp tables but hey, who cares if it does the job :)

Database Table Referencing Several Records

I'm looking for some guidance as to how to set up a database I am creating. I think the best way to ask the question is to describe the specific scenario:
I have a database that will hold information about student-employees at a school.
I have one table called "Semesters" that contains information about a specific semester (e.g. "Fall/Spring/Summer", year, etc.).
I have another table called "Employees" that contains information about a specific student-employee (e.g. name, jobTitle, startDate, endDate). I would also like to have a reference to the "Semesters" table indicating which semester(s) the employee was hired. So, for example, one column in the "Employees" table would tell me that this specific employee was working during the "Fall2010, Spring2011, and Fall2011" semesters.
The problem is that I don't know how to reference several records in one field.
I am sure that this is a fairly common scenario, I'm just not sure how to go about it.
Answers that reference MS Access or SqlServer would be excellent.
Thanks.
This sounds like a many to many relationship. In such a case you would likely utilize a junction table.
Employees (empID, name)
1 bob
2 moe
3 george
Semesters (semID, name)
1 fall 2010
2 spring 2010
EmploymentHistory (empID & semID)
1 1 (bob was employed fall 2010)
1 2 (bob was employed spring 2010)
2 2 (moe was employed fall 2010)
You can accomplish this with several foreign keys to the Semester table (not Semesters) from the Employee table (not Employees).
If you want to keep track of the semesters that an Employee has worked, I'd normalize that into a WorkHistory table that's one-to-many with Employee and many-to-many with Semester.

Resources