Training Database Design in SQL using C#, sql, asp.net, exchange - database

For a possible solution using Active Directory and Exchange see my post below.
We would like to create a training database in SQL which we can use for our internal training sessions of our employees. Unfortunately I do not have any experience in database design and did not have a chance to buy and read a proper book about this topic.
I have just started to create a database after reading a few tutorials online and would like you to review my design and provide me with some feedback if I have started more or less correct.
The courses table will store our training courses with their duration, capacity and a small description of what you will learn on this course. The training session table will be used to link a course with a specific training and a date when the training will be done. The trainers are colleagues who provide the internal courses.
The attendance table stores the training session id and if an employee attended the session or if he could not.
Please find below our database diagram:
alt text http://img8.imageshack.us/img8/2464/trainingdb.jpg
Later on we would also like to store the job position a training course is relevant for.
For example our network introduction course is relevant for a Level 1 Analysts, a Level 2 Analysts and Team Leaders. Our ITIL course is relevant only for a team leader.
How would you store this information? Would you use a separate table with the positions and use a many to many relationship for this?
Many thanks,
Mathias

The structure seems fine. I'd suggest adding one more foreign key relationship, though: Attendance.EmployeeID should reference the Employee table.
Attendance doesn't need its own primary key. The combination of employee and session uniquely identifies it (a given employee can't attend a given session more than once, can they?). You should probably use the two ID columns for those as a composite primary key.
Do courses really have a capacity, or is it a session which has a capacity?
What's the UpdateTime column for?

A bit simplified, does not account for enrolment, but may help you with ideas.

Below an explanation of the tables
We use the module category, module type, course, programme, training method and post work tables to categorize the training module using dropdown lists. The relationships are 1:n.
The module <-> employee relationship is m:n. As you can see from the model, the intersection table is Trainer where we define the additional property of Priority to allow us to define trainer priorities for a module.
The training module <-> role relationship is a many-to-many relationship as a module can be relevant to many job roles. The intersection table is RoleRelevance and we define for each role required, recommended, probation and hide properties.
The training request table keeps a record of each training request that has been requested. We also have new starter requests were we do not have a domain profile / SAM we can link the request to.
The employee table is being populated from our domain controllers with AD queries while employees are requesting a training or trainers are being defined for a module. The table includes the employee smtp address used to send invitations. See my other stackoverflow posts for a code sample how to get this data.
We create meeting invitation with managed EWS for the employee, line manager, trainer and resource/room. The invitation id and status (accept/decline/unknown) are stored in the EmployeeInvitation, TrainerInvitation and ResourceInvitation tables.
Training sessions we create are being inserted into the training session table.

Related

How to persist data in microservices?

I am getting started in microservices architectures and I have a couple of questions about the data persistence and databases.
So my understanding is each microservice has it's own database (not necessarily, but usually). But given that case, consider a usual social media platform with users, posts and comments. There will be two microservices, a user's microservice and a posts' microservice. The user's database have a users table and the posts' database has posts and comments tables.
My question is on the posts microservice, because each post and comment has an author, so usually we would create the foreign key pointing to the user's table, however this is in a different database. What to do then? From my perspective there are 2 options:
Add the authorId entry to the table but not the foreign key constrain. If so, what would happen in the application whenever we retrieve that user's data from the user's microservice using the authorId and the user's data is gone?
Create an author's table in the posts' database. If so, what data should that table contain other than the user's id?
It just doesn't feel right to duplicate the data that is already in the user's database but it also doesn't feel right to use the user's id without the FK constraint.
One thing to note, data growth is quite different
Users -> relatively static data.
Posts & Comments -> Dynamic and could be exponentially high compared to users data.
Two microservices design looks good. I would prefer option-1 from your design.
Duplication is not bad, In normal database design this is normal to have "Denormalization" for better read performance. This is also helping in decoupling from users table , may help you to choose different database if require. some of your question what if users data is missing and posts is available, this can be handle with business logic and API design.

Laravel: Mixed Users Database Schema

I am working on a database schema for a Laravel project and am unsure of how to design it properly. I have mocked up the majority of the schema, but am unsure of how to make the last leap to properly include users.
There are 8 tables, and the business model is meant to keep track of medical practices, the doctors assigned to them, their patients, the RXs that are written on those patients and what Meds are written in the prescriptions.
Where I come into the issue is that our users table will include our business' staff, representatives, sometimes the distributors of those representatives, and a select few doctors that will want to view their own production. So the users is a mixed bag of people spread across the Distributors, Reps, and Doctors tables with a few of our staff thrown on top of it. Thus far, I have created a 'UserRole' column in the Users table to reflect what the user's capacity is, but that is all.
Can someone assist me with how this should be reflected in the schema, and any thoughts on how to optimize the schema overall if they have any ideas? I am very, very new to both database design and Laravel. Thank you!
There are usually a number of ways to go about this but I followed an approach recently that provided a lot of flexibility for me.
So my simple approach is to keep the Users table as a base. With the minimum required user data like name, username, password, email, phone number, created_at etc and the User ID (user_id) would serve as foreign key to be used anywhere else that actually apply to all users.
From there, when creating a doctor profile, or a distributor etc, you follow the same user structure.
Hope this helps.

Data warehouse modeling - consistency between two fact tables

I have some trouble to design my data warehouse. Here's the context :
Financial people register our deals and report a financial snapshot every month. When they register new deals, they also indicates some information like which equipment is sold, at which customer, etc. (our dimensions).
Project managers add additionnal data to these deals with milestones information (startup project date, customer acceptance date, etc.), also on a monthly basis.
Finance will only use finance information, Project Manager could use both type of information.
Based on this information, I have many possible scenarios, which is the best ?
1st scenario : star schema
In this scenario, I have two separate tables for Finance and Project management. But the thing is that I will have to duplicate reference to dimensions (equipment, customer, etc.) as it is Finance that declare deals and that information have to stay consistant for a same deal.
First Scenario Schema
2nd scenario : one common table
As we have the same granularity (both are monthly snapshot), we could merge Finance and Project management information in a single table and proposes two views to the users. But I fear that it will become a mess (different enterprise function in a single table...).
3nd scenario : snowflake schema
We also could add a "Deal" table, containing all references to other dimensions (customer, equipment, etc.).
Third Scenario Schema
Thanks in advice for any usefull advice !

How to visualize relation between objects in a database?

I have a database which I want to visualize in some kind of tool. Let me explain the basic:
Company A does business with Transport Company A and Transport Company B.
Transport Company A does business with Company A, Company B and Company C.
Company C does business with Transport Company A and Transport Company B.
As you can see every Company does business with different Transport Companies and vice versa. These relationships can be implemented in a database, and when drawing a visual model on paper this is also very easy.
Of course the model should contain hundreds of Companies and Transport Companies. So I want to have a visualizing tool, where a overview of these relations can be displayed.
My question is which tools can be used for realizing this?
I think you want to look at Microsoft Visio (get the 2010 version. 2013 is almost unusable from a database standpoint).
But if i am assuming correctly, you want to create a table per company. Don't do this! this can cause redundancy and data integrity problems. you want to create just one table and create what is called a unary many-to-many relationship. This is relationship that can be translated to many different rows can relate to many rows in the same table. I won't go into more detail unless you want me to, as i spent a week or 2 in my Database Design course last month just on many-to-many relationships and gets kinda complicated.

What's the best pattern in data modeling for relating real people to app users?

This is a design question.
I need to come up with a Data Model for a small app and I'm looking for the best approach.
A simplified version of the business I'm trying to model has the following entities:
Assignments: These are like projects, they have a start date, end date and a team of people associated
Workers: These are the people that execute assignments. A given worker can only be associated to one assignment at a time. Many workers can be associated to the same assignment at the same time (for big projects).
Manager: There's basically few managers in this business, who are in charge of allocating workers into new assignments as they come.
Then, there's the Web app that the Manager will use to manage who does what, i.e. which worker gets assigned to which assignment. The Workers will also use this app to register expenses associated to their assignments.
So in the context of the Web app, there will also be the User entity, and both workers and the manager will have their users to access the app.
My question is:
What's the best data model to support this (simple) system?
I picture this model:
USER (id, username, password, ...)
PERSON (inherits from user + name, email, etc...)
MANAGER (inherits from person + extra fields for manager only)
WORKER (inherits from person + extra fields for worker only)
What I don't like about this model is that every person must have a user. Maybe that happens today with workers and managers, but i will then add "customers" to this system, which will also have people associated that won't access the site, so they won't have a user.
Is there a better approach? Is there a standard approach without inheritance maybe?
Update
Ok, based on the model suggested above and completing with some extra info about this particular business, here's the (basic) model.
PERSON
id
email
passmd5
role_id
firstname
lastname
...
ROLE
id
description
PERMISSION
id
description
ROLE_PERMISSION
role_id
permission_id
COMPANY
id
name
contact_name
contact_email
ASSIGNMENT
id
customer_company_id
start_date
end_date
location_lat
location_lng
location_description
MACHINE
id
brand
model
description
PERSON_MACHINE_EXPERTISE
person_id
machine_id
Here's some extra information about the business to help understand the whole diagram:
The business consists on sending people who are experts in some kind of machinery to different locations around the world, to give service to a given customer.
There are people who are the "experts".
There are people who are the "managers" (probably just one, but there could be more).
There are assignments (a job, basically, which requires expert people to complete the job, sometimes more than one expert).
There are customers, who are basically companies, not people.
There are machines.
There's information about which person is an expert on which machine.
Makes sense? Any ideas that may improve this?
To approach this problem without inheritance you could perhaps define a Person class and a Role class, with every Person having a list of Roles (or a single one based on the needs of the domain).
The Manager and Worker concepts will then fall under a Role class, with some people having the Manager role (the managers) and others the Worker role. This will simplify the management of all Person objects as modifying their status, permissions and such being reduced to updating the role in the system. It will also give you the flexibility of adding new Roles without having to modify the source: simple create a new instance of Role, say Customer and assign it to whoever Person is needed.
Lastly, you could create a another concept, call it Permission that defines what can a Person do, with Worker and Manager roles having a CanAccessWebApp permission (and the Customer not). This will offer you a lot of flexibility in the long run while keeping the overall relationship design rather simple.

Resources