Primary Key and Functional Depe - ms-access

I have a table below and I would like to get confirmation on one of the functional dependencies.
Taylor Johnson is the name of two twins who live in the same house.
Student ID is a unique ID and hence it is the candidate/primary key.
But Student ID doesn't functionally determine Student Name or does it? I don't think it does because knowing student ID wouldn't tell you which Taylor Johnson you are talking about. If that is the case, then I cannot say that my candidate/primary key (Student ID) functionally determines all other attributes in the table even though it is a unique key. Doesn't it then violate the definition of a primary key? Thanks for any insights in advance!
Student ID Student Name DOB Street City State Zip
1 Taylor Johnson 4/10/1988 Meadow Raleigh NC 27606
2 Taylor Johnson 4/10/1988 Meadow Raleigh NC 27606
3 Kim Blake 2/10/1998 Crescent Cary NC 27512

Related

Find similar name in view based on other table

I have one view from my database contains a lot of customer name and address
ID Name Address Event
A1 Jon California Hockey
B3 Mark Texas Marathon
B4 marc Texas Marathon
A5 Jacobus Florida Soccer
C2 BILLy ALASKA Basket
and then one table master customer
Name
JOHN
MARK
JACOB
BILLY
I want to remove similar/duplicate name based on same address and event and repair misspell name automatically based on same characteristic then insert it into new table called true_customer so teh resut will be like this
ID Name
A1 JOHN
B3 MARK
A5 JACOB
C2 BILLY
Note:
I can't use function like levenshtein etc this case

Show All Records For Given Field Filter In Access 2010 Table

Hopefully this will make sense...I have a table in Access 2010 that contains a list of suppliers and their point of contacts at the supplier and where I work. The POCs vary in number, anywhere from 1-4 up to this point. The table is set up so each POC is on a separate line.
The supplier could have one contact but work could have three different contacts and vice versa.
What I want to happen is when I select a value from a combobox on a form, all the related POCs need to be shown instead of cycling through them one by one.
For example, Supplier1 has two POCs at their facility and we have three at our facility. I would like to have the combobox find Supplier1 in the table and then show all the contacts for that supplier (their facility and ours) in a textbox.
The user will be able to edit the contact information and, if it is not too difficult, would be able to add/delete a contact.
I'm sure a question similar to this one has been asked before, however I have been unable to word it correctly to find a solution through google searches/this website. I'm comfortable enough with VBA to use that if required but am by no means an expert. I am completely unfamiliar with SQL and would like to avoid going that direction if at all possible.
I have to be careful with any data I provide but will do what I can if you need to see the data or anything like that.
Supplier Code Part Supplier Contact Procurement Contact QC Contact
Ajin AKVN Patrick Yong Jack
Ajin AKVN Chase Yong Jack
Autoliv AMNP Seatbelt Daryl James Lewis
Bosch AG48 Hancheul Kevin
Carlex AKJ5 QTR Glasses Bob Joy Zack
Continental ANKC Jacob
KSR C03A05 Brake Pedal Jose Paul David
KSR C03A05 Brake Pedal Jose Paul Gary
KSR C03A05 Brake Pedal Jose Paul Steven
KSR AG5Z Accelerator Pedal Jack Paul David
KSR AG5Z Accelerator Pedal Jack Paul Gary
KSR AG5Z Accelerator Pedal Jack Paul Steven
KSR AG5Z Accelerator Pedal Cory Paul David
KSR AG5Z Accelerator Pedal Cory Paul Gary
KSR AG5Z Accelerator Pedal Cory Paul Steven
Your table needs heavy normalization (see e.g. What is Normalisation (or Normalization)? or http://r937.com/relational.html )
I would suggest (Note: I'm not sure about the Supplier/Code/Part relation) :
- tSupplier
SupplierID SupplierName
1 Ajin
2 KSR
- tParts
PartID SupplierID Code Part
1 1 AKVN
2 2 C03A05 Brake Pedal
- tContactTypes
TypeID Type
1 Supplier
2 Procurement
3 QC
- tContacts
ContactID SupplierID TypeID ContactName
1 1 1 Patrick
2 1 1 Chase
3 1 2 Yong
4 1 3 Jack
and so on.
The first column of each table is the primary key, an autonumber field.
All other ID columns are foreign keys, linking to a parent table.
Now you can have a combobox for the Supplier, which gives the SupplierID.
With that, you can filter the Contacts and show them in a datasheet subform.
Either all in one table, with the ContactTypes as column, or in three subforms, each filtered by one ContactType.
To be able to add new contacts, use the BeforeInsert event to assign the current SupplierID.

How do I group by first name in MySQL?

I have a table where there is a full name column. I want to get either the unique given name or given names sorted by how many times they occur.
fullname
-----------
Barack Hussein Obama
Michael Jackson
William Jefferson Blythe
Michael Bloomberg
so the output will be either
Barack Hussein Obama
William Jefferson Blythe
Or
Barack Hussein Obama
William Jefferson Blythe
Michael Jackson
Michael Bloomberg
Or
1|Barack
1|William
2|Michael
Something like that. My aim is to see the foreign students in my database. I only have their full name to make a guess.
You can use SUBSTRING_INDEX(fullname,' ',1) to extract the "given name" as per your definition.
You can then use this for grouping or sorting as you seem fit, e.g.
SELECT COUNT(*),SUBSTRING_INDEX(fullname,' ',1) AS givenname
FROM yourtable
GROUP BY givenname;

Advice on building a database table

After doing some research I need some advice. This is a small project which allows teachers to post assignments online, and students to view/submit those assignments.
Students can have multiple courses assigned to them, so my question is: What is the best way to set up a table?
Example 1:
student courses
John Smith Math, Chemistry, English
Mary White Math, Biology
Example 2:
course students
Math John Smith, Mary White
Biology Mary White
Chemistry John Smith
English John Smith
I apologize in advance if this is a noobie question, but I want to avoid doing things wrong from the get-go and I'm open to any and all suggestions!
Thank you for your time.
It's generally not suitable to put more than one item in a column in a relational database. So create a table like this:
course student
Math John Smith
Math Mary White
Biology Mary White
Chemistry John Smith
English John Smith
Then, you can use this table in JOIN expressions to retrieve the info you want. You may want to have additional tables that describe the essential information about courses and students. Something like:
course instructor time
Math Albert Einstein 10:30
and
student id_number phone
John Smith 1234-5678 555-1212
...or whatever information you need to keep about courses and students.

The conceptual process of populating related tables in a database (MySql) from a CSV file

I'm new to relational databases and all the material I've read covered primary and foreign keys, normal forms, and joins but left out to populate the database once it's created.
How do you import a CSV file so the fields match their related table?
Say you were tying to build a beer database and had a CSV file with each line as a record.
Header: brewer, beer_name, country,
city, state, beer_category, beer_type,
alcohol_content
Record 1: Anheuser-Busch, Budweiser,
United States, St. Louis, Mo, Pale lager,
Regular,
5.0%
Record 2: Anheuser-Busch, Bud Light,
United States, St. Louis, Mo, Pale lager
Light, 4.2%
Record 3: Miller Brewing Company,
Miller Lite, United States, Milwaukee,
WI, Pale lager, Light,
4.2%
You can create a "Brewer" table and a "Beer" table. When importing how does you connect the primary keys between the tables?
You define Primary and Foreign key relationships when you create the tables. Once they've been set up you can just about forget them, unless the database throws an error if you try to do something that violates the relationships.
For example, if you try to add a record into the child (foreign) table that does not have a value in the parent table, the database will complain, if the relationships are set up correctly.
e.g. Adding Record 1 into the Beer table will fail unless you have already added
Anheuser-Busch into the Brewers table.
A suggestion on setting up your tables:
Brewer
id bigint
name varchar(50)
country varchar(50)
state varchar(10)
city varchar(50)
Beer
id bigint
brewerId bigint
name varchar(70)
category varchar(50)
type varchar(50)
alcohol decimal(3,1)
Set Brewer.Id as the Primary Key of the Brewer table.
Set Beer.Id as the Primary Key of the Beer table.
Then create a foreign key relationship between Brewer.Id = Beer.brewerId
Then manually add the brewers (because there's not too many of them)
Brewer
1 Anheuser-Busch United States Mo St. Louis
2 Miller Brewing Company United States WI Milwaukee
Then fiddle your CSV file to replace all the brewer details with the brewer's respective id, and use that to populate your Beer table:
Beer
1 1 Budweiser Pale lager Regular 5.0
2 1 Bud Light Pale lager Light 4.2
3 2 Miller Lite Pale lager Regular 4.2
So: The brewerId links each beer to a brewer in the brewer table. That is the foreign key - each beer automatically gets all the brewer's details because it's brewerId matches the brewer's id (and you set that relationship up when you created the tables).
Beer 1 (Budweiser) belongs to Brewer 1 (Anheuser-Busch)
Beer 2 (Bud Light) belongs to Brewer 1 (Anheuser-Busch)
Beer 3 (Miller Light) belongs to Brewer 2 (Miller)
This lets you do really cool suff. Say Miller was bought by another company... all you have to do is change the details in the Brewer table, and voila - all the beers that were owned by Miller now belong to the new brewer. You can also calculate sales by Brewer, state, etc.
The basic rule of thumb is that Primary and Foreign keys are like a Parent - Child relationship. The Child stores the Parent's id. This way each Parent can have multiple Children. It can get a WHOLE lot more complicated, but this will give you a very good starting approach to most of your database solutions.