I am trying to setup tables in a MySQL database for one of my class projects. The project involves us submitting html forms to a database. So currently I have a table for every form that I am currently submitting the to database. I also have a user table which holds user information.
My questions is I want to link the forms tables to the user table, but I am trying to avoid having to create a linking to table from each form table to the user table separately. Is it possible to not do this?
I am assuming each user submission is a row entry in the Form tables? Without the user_id column already in your schema, how did you differentiate which entry is which user to begin with?
For your question, it depend on what you want to output with these form tables. If all you want to do is to output the content of the forms for a given user, then adding a user_id column to each of your form table will suffice.
However, if a form requires some additional information about the user in the Users table, might as well add the user_id column as a foreign key to the Users table that you can join with.
I don't see what is the restriction to "linking to table", unless your have a lot of Form tables
Related
The database i'm trying to create have four tables. tblPatient information, tblparasitology tests, tblserology tests and tblbiochemical tests. All the later three tables are related to patient information table. What i want to ask is that, is there a problem if i use the primary key in the table patient information to foreign keys of all the other tables? in other words how many tables (foreign keys) can be related to a primary key on one table?
There is really no practical or particular limit here.
however one tip, one concept to keep in mind?
While you can setup all these related tables, to create forms that edit the data?
Each form is STILL based on the one base table.
So you can create a form based on tblPatients.
So allow view and editing and adding of say tblserology results?
That will become a sub form. NOTE VERY careful here that the form tblPaitent is based ONLY on that one table. And the child table (and child form (ie: sub form) tblserology will ONLY be based on tblserology table. So the forms to hook up, wire up the relatonships between the tables are STILL only based on the single table.
To allow editing of related data, you thus use sub forms. If you do this correctly, then no code is required to edit and display and maintain say display of test results for a given patient.
So each and all tables will have a primary key (auto number id).
To realate a child table back up to a parent table, you create a plane jane long number column. This value will be automatic setup for you if you follow the above advice for a main form, and then a sub-form for the child table data.
I'm new to MySQL and databases, and this question is more about best practices than exact code.
If I want to create a database that let's users register an "account" so they are then able to access and track the value of virtual goods in a video game, including selecting items from a list and marking them (thus requiring the choices to be associated with their account), Is it better to store the users choices in the same table that holds their username/account-info? Or should the information be stored in a separate table with a reference to the associated account?
Or should I create a table for each user, instead of having one for registration/account info, and another for data, etc.?
Does the best practice for this vary with the expected number of users and/or amount of data?
Is there a way to set it up that allows for handling growth from 2 or 3 users to hundreds?
The answer is to create one table for accounts, one table with choices that are referenced to that account with some type of token.
There's no reason to create a new table for each user. You should have one table, and differentiate between the users using the data in the table (e.g., the userid, the username, etc).
I am trying to design a table for maintaining USER information. Here is the table design as per the below image
Since the table has created_by and last_updated_by columns and they are the foreign keys to the user_id column of the same table, I am having multiple issues especially with Hibernate. When a user is signing up to the application, created by will be same as user id. Similarly, when the user is modifying his profile, the last updated by will be the same as user id.
How best can i tweak this design so that i still have the information about who created this record and updated it.
I am very new to using Access and databasing in general. I need to set up a database to manage car loans. I currently have the following:
A form which displays the information each individual customer
A button at the bottom of the form, titled "View Customer History"
A table with the records of all loans, sorted by car registration number
What I need to do is have access create a custom query which will display all the items from the table containing the loan records that have been rented by the customer that is being displayed in the form. I am aware that creating queries manually is an option but seems impractical due to the number of new customers loaning cars all the time.
I hope that the question made sense and appreciate any help I can get.
I would approach the task in this way:
Create two tables called "Customers" and "Loans"
"Customers" table should have unique records for each customer. One of the fields in this table will be titled "Name" and should obviously contain the names of the customers. Make this field the Primary Key. The other fields will contain other information related to the customer
"Loans" table will have a field called "Customer" which stores the names of the customer loaning out the car. Link this field to the Primary Key of the "Customers" table. The other fields will contain details relating to the loan
Now your form (name of form: "Information") is linked to the "Customers" table and shows all the information stored in the table. Name the field on the form containing the name of the customer as "CustomerName". At the bottom of the form you have a button for viewing customer history
Create the query: SELECT * FROM Loans WHERE Loans.[Customer] = Forms!Information!CustomerName;
Assign this query to the 'On Click' event of the button on the form
There are of course other ways of achieving the desired results, but the way described above is also sufficient.
I have two tables (persons and projects) which are in a many-to-many table, thus linked together by a third table persons_projects
In ms access I now created a form showing data from the projects table.
What I want is to have a subform showing all persons- datasets which participate in this project. In this subform it should also be possible to add (or delete) persons from this project—a drop-down seems the best choice here.
How can I do this? I’m able to show all participants, but I’m not able to add them. seems like I have the “insert into view” problem again, since I need persons and persons_projects to show the correct datasets. but as I’m only changing/adding rows in a single table (persons_projects) I don’t see why access is bitchy again.
You should not need persons, only persons_projects. I assume that persons_projects consists of:
person_id -> FK ) Combined as PK, perhaps, if not, an autonumber PK
project_id -> FK )
and (recommended) a datetime stamp and user field.
The subform is set-up with a Link Child and Master Field of project_id, which will be automatically completed by Access, and a combobox similar to:
Control Source: person_id
Row Source: SELECT person_id, surname & " " & forename, some_field FROM persons
Bound Column: 1
Column Count: 3
Column Widths: 0cm;2cm;2cm
Edit re Comments
It is possible, though often a little more difficult, to include both tables and have an updatable recordset, the query (view) should include both project_id and person_id from the junction table.
Sounds like persons is the driving dataset here since you want to be able to link it to multiple projects as well as delete the person record.
Base your form on the Persons table. A subform should be based on the person_projects table and linked by the corresponding id's. You can use a combo box on the projectid in the subform and have some other field displayed so the user can identify the project (name?). You may want to show all the project data for each project on this form, but you may find it getting very confusing to the user. Having a separate form that you can 'pop-up' to give more project information may be a better choice.
If you want to delete a person, you can just delete from the persons table, but you need to decide if you want any orphan records in the person_projects table (Which you shouldn't). It's easy in Access to establish a link with referencial integrity (cascading update and delete optional). It's up to you as to how robust this needs to be.