Writing the functional dependency - mysql

First module is User module. Administrators, students, lecturers or guests are users who benefit from the system and they take part in this module. Administrator will assign role as student or lecturer for each user. Each role has different privileges that is lecturer can upload the assignment and course materials, create the online quiz and single upload file. Users have information such as user ID, date of registration, date of latest logon, login account, password, first name, last name, and others details needed. Just say that student ID and lecturer ID cannot be the primary key. Therefore, how am I suppose to state that assignment or quiz ID is functionally dependent on lecturer when assignment ID and my quiz ID is a primary key? Based on my functional dependency, I'm not really sure how am I suppose to relate them to functional dependency?
Entity: User
User(user ID, student ID, lecturer ID, guest ID, course ID, assignment ID, quiz ID, file upload, date of registration, date of latest logon, login account, password, first name, last name, e-mail, birthdate)
Functional dependency
user ID -> {student ID, lecturer ID, guest ID, date of registration, date of latest logon, login account, password, first name, last name, e-mail, birthdate}
lecturer ID -> {course ID, assignment ID, quiz ID, file upload}
Full dependency
user ID, lecturer ID -> {student ID, guest ID, course ID, assignment ID, quiz ID, file upload, date of registration, date of latest logon, login account, password, first name, last name, e-mail, birthdate}

First, a functional dependency in the form A->B means that, given one value for A, we can determine one and only one value for B. Both A and B represent sets of columns. (That's why they're written in uppercase letters.)
Keys really have nothing to do with how you state a functional dependency.
If "lecturer id" functionally determines "assignment id" then the FD is "lecturer id"->"assignment id". If "lecturer id" also functionally determines "quiz id", then another FD is "lecturer id"->"quiz id".
If you want to write that more compactly, you can state the two FDs like this.
"lecturer id"->{"assignment id", "quiz id"}
If you assign the letters L, A, and Q, you can state the two FDs like this.
L->AQ
Braces are usually omitted in this notation, because everyone knows they're supposed to be there.
I'm not sure what you're trying to get at with your last section. But in it, the section labelled "Functional Dependency" doesn't express any dependencies; "Full dependency" doesn't express full dependencies, but might express some partial dependencies; "Partial dependencies" doesn't express any partial dependencies; "Transitive dependencies" doesn't express any transitive dependencies.

It is not clear what you are trying to accomplish. And you don't seem to understand the steps that we go through in schema design.
First we determine what application relationships we are interested in. Eg "user [userID] has role lecturer" or "user [user ID] has first name [first name] and password [password] and ...". Each gets a base relation that holds the rows of values that are related that way.
For each relation the meaning of its application relationship determines for every column what sets of columns it is functionally dependent on. Then we find a minimal cover for that. This determines candidate keys. We can pick one candidate key as primary key.
This determines full and partial dependencies of non-prime columns on each candidate key. This allows us to normalize to 2NF by decomposing our relation to separate the non-prime column partial functional depencies on candidate keys into separate relations.
Just say that student ID and lecturer ID cannot be the primary key.
Therefore, how am I suppose to state that assignment or quiz ID is
functionally dependent on lecturer when assignment ID and my quiz ID
is a primary key?
This doesn't make sense. We can't determine the candidate keys until we determine all the functional dependencies. Also: Do you mean {studentID,lecturerID} "can't be the primary key", or do you mean {student ID} "can't" and {lecturer ID} "can't"? Also: What do you mean by "can't"?
We say assignmentID and quizID are functionally dependent on lecturerID in some relation by:
{lecturer ID} -> {assignment ID}
{lecturer ID} -> {quiz ID}
We can combine right hand sides (determined column sets) with the same left hand side set (determiner):
{lecturer ID} -> {assignment ID, quiz ID}
But there other rules like that for finding a minimal cover.
Based on my functional dependency, I'm not really sure how am I
suppose to relate them to functional dependency?
This doesn't make sense. Relate what to your functional dependencies?
If the only functional dependencies for "User" are the ones in the transitive closure of "Functional dependencies" (ie the only FDs are the ones that must be there when those ones are) then a minimal cover is
{user ID} -> {student ID, lecturer ID, guest ID, course ID, assignment ID, quiz ID, file upload, date of registration, date of latest logon, login account, password, first name, last name, e-mail, birthdate}
and the only candidate key is
{user ID}
and there are no non-prime column partial dependencies on a candidate key.

Related

Display details when user click table row

I have following tables in my Database:
Student (student_id, email, name, ...)
Course (course_id, course_name, ...)
Enrollment (student_id, course_id, marks,...)
I Want to implement this functionality:
When admin want to search list of all students in particular city,
the list is displayed as HTML table.
This can be implemented by just querying student table.
When admin click on any row (from the table we have displayed in 1.)
then admin should see list of all courses the student has enrolled
in.
My question is how should I implement this?
I can think of following ways:
Way 1:
https://stackoverflow.com/a/45135144/3494107
I need to have some way to identify which row admin has clicked, for this I can pass the student_id also in the table in result for 1 (display list of all student) but as student_id does not convey any information to admin about student I can just hide it in data-* attribute of <tr> or in <a href=/enrollment/${student_id}> so that I can use this to identify which row admin has clicked. Some of my friend told me that I should not expose surrogate key, this is bad for security. So is there any way I can associate this student_id to table row but hide from the user or it is OK to expose surrogate key content to user?
Way 2: I can create a temporary table containing all student from particular city in DB and assign the row ID to it. Now in result I can add this row ID for each row into data-* attribute. This row ID does not convey any information about what is actual student_id and I can use this row ID to query temporary table to get actual student_id which I can use to search in enrollment table. Now I need to delete this temporary table when user navigate away from current page (go to other functionality), now how should I detect when user have moved away from this page?
I want to understand what security issue I can have if I expose surrogate key to user?
No security issues as such if you expose the student_id but at business point of view it's not much acceptable.
If these tables are only viewed by admins then it is not a problem in either way.
If these are viewable by even by a guest then better not expose the student_id. Not for the security of your database but for the security of your business. It might expose your strength and weakness.
You can use student_registration_no instead. It might be slow, considering a VARCHAR entry, but not humanly detectable.

Database Schema for group

I have a simple user and group database.
User: uid(pk), name, password ( don't worry about password in plain)
Group: gid(pk), name, owner_uid
Member: uid (fk), gid (fk) ( a user can belong to multiple group)
Now, I do not trust my database administrator and want to encrypt/secure specific coloumns so that db admin cannot be able to add any existing uid to any gid. How I could modify my scema and which coloumn I should encrypt.
I have a encryption key which is assumed to stay secure and I wanted to utilize sql queries also so cannot complete encrypt the tables and store as blob.
I think you can not perform this requirement with database constraints. You can manage it by programming. However if you write some triggers to handle it, your (bad) administrator can access triggers too.
Add an extra column to Member like key_info.
In Insert: make a hash code (like sha256Hex) with combination of uid and gid and specific salt. And insert with uid and gid into Member.
In Selects from Member: you have an extra difficulty. You should select the records (from Member) that have correct hash code.
If you have a big and complex salt and your administrator can not access the salt (as you said in comments), he/she can not find the codec algorithm. So if he/she added some records into Member, your codes ignore the added record in selects, because the key_info can not be true.

Storing Multiple choice answers of a Module Options Form in a Microsoft Access Database

I currently am trying to work out how to create a relational database for a University Module Options form. First you enter your student ID, Name, Surname and select your degree programme e.g. Human Resource Management then choose multiple modules through the form using checkboxes until the total credits for each semester for each programme is chosen.
However in choosing multiple modules and in being a relational database design i am unsure of how to store these multiple answers in the Student Options table as shown below.
I currently have the tables of
Table: Student
Field Names:
Student ID (primary key)
Name
Surname
Table: Programme
Programme (primary key)
Semester 1 Credits (different programmes allow different amount of credits )
Semester 2 Credits (different programmes allow different amount of credits )
Table: Module
Module ID (primary key)
Module Name
Credits
Prerequisite
The last table is one i am struggling with as after the modules are chosen from the form they will be stored in this table and currently have this...
Table: Student Options
Student ID (primary key)
Programme (link to programme table)
However i am unsure what fields to have to store them in without being too cluttered and still having a link to the modules table as shown below which are all stored individually.
Does my modules table need to have a relationship link to the student options table to be a relational database ?
How would i store the multiple modules chosen into the student options form?
Thanks
As for your core problem, I think the database design outlined below should be sufficient:
You should not store both, the modules a student selects and the programme he is enrolled in in the same table. Instead do it like outlined above.
The programme a student is enrolled in should just be a foreign key in the student table, therefore giving you a one-to-many-relation (This is a crucial point though, because this means any one student can only be enrolled in one programme! If your database has to be able to have one student be enrolled in more than one programme, you need a many-to-many-relation there too.).
The modules should be related to a student via a middle table (I called it StudentModule in this case), therefore giving you the desired many-to-many-relation. What you now have to do of course is check via code, if the module isn't already selected by the student (as well as all the other small and big details there are...). But this you would have to do with any database design as far as I know.
As you can see, I also inserted a middle table for the module to programme relation. This is because I assume that one module is eligible for multiple programmes. By relating modules to programmes in this way, you can then check for stuff like "can this student elect this module", ...

Reference tables instead of Enum fields for lookup efficiency

In my application I have a user which has a profile and an address. The relationship between those tables are:
users: id, type, registered, email...
profiles: user_id, address_id, first_name, last_name, gender, status, etc..
addresses: id, city, street, house_number, apartment
Those tables have some Enum fields on them, but I think it might not be efficient at-all since I'm going to do some intensive user's lookup based on their address and profile so I thought maybe I should use reference tables instead? (I also gain the indexing with an integer which is better).
For example, In profiles I have a status enum field which gets the following values for now:
single
married
widowed
divorced
so I thought about maybe having a statuses table and a foreign key on profiles - status_id.
Another dilemma about this is should I have a reference table for a gender as-well? Currently I only accept male and female values in my enum field for gender, but maybe in the future we will want to add a transgender or anything else. I will also do an intensive user lookup based on gender of-course. Should I also extract it into a reference table?
Enums are internally stored as numbers. The data like gender or status in profile table doesn't get modified very often. So I personally would prefer enums. This would avoid the referencing overhead.
However, it has its own disadvantages.
Please refer to http://chateau-logic.com/content/why-we-should-not-use-enums-databases to know why not to use enums. If you are using multiple languages in your application then enums are a definite NO.

Referring to super parent or as a separate entity?

I have this person table as super parent,
id
firstname
lastname
email
telephone
...
...
and user table as a child
id
person_id (FK)
password
username
screenname
...
...
They must be 1:1 relationship, because an user cannot be repeated twice. and so the email in the person row must not be repeated twice.
Then I have this message table which stores messages from anyone,
id
firstname
lastname
email
telephone
subject
content
...
...
but you can see that firstname,lastname, email,telephone are duplicated in message table.
so I am thinking to refer it to person table like this below,
id
person_id
subject
content
...
but then it does not seem right, as a person with the same email, name, etc can send message to me as many times as they want. so the details he/she provides can be repeated.
so should I make message as a child of person the parent or they should be separate entities?
or any better suggestions to solve this problem.
You have to decide what you want your system to do. Do you want old messages to reflect someone's new name or do you want each message to have the name (and other details) which were in effect when the message was created?
If you want the system to only reflect the current personal details then all your message needs is a foreign key to PERSON.
If, on the other hand, you want your messages to look the same way for all time, even if the person who sent them changes their name, email address or other details, then you have to find a way to keep the historical information. Two obvious choices would be (i) denormalize the person details down to the message - as in your current design or (ii) keep a history table of PERSON with snapshots of each combination of personal details with MESSAGE referring to the appropriate person history record with a foreign key.