I have a Users table a Network table and Network_tab table. I need to associate users with a Network_tab and know what network it is for - (A Network_tab can be on any Network.) The best way I can see of doing this to ensure I can associate a user to a Network tab for a Network is to created a User_Network_tab table, which contains the UserId, NetworkId and Network-tabId.
Would it be sensible to assume that indexing all three fields within the User_Network_tab table would be the best option and would not cause an slow down when selecting al the details out? I need more information about the User the Netowork and the Network_tab than just the Ids.
Any advice of a better way in doing this would be appreciated as well.
Thanks Guys.
Related
For a project, I have a database with some tables.
All of them are related between them. The table organization has a relationship with offer and user, etc.
However, I have some columns that only serve to link two tables together.
Take a look at the diagram. I use users_interests to link the user to his interests. Same thing for badges and group.
It doesn't really feel efficient. When I try to get the interests of a users, I must first go through requesting the user interests and from that, require the interest details.
Is there a way that I can request the interests of an user without having to go through a second table ?
https://dbdiagram.io/d/5da3f119ff5115114db53551
There's a couple things you should consider when looking at this question/functionality and what you're going to be doing with the data.
Do you have a unique set of interests that will remain the same or be added to, without duplicates?
Do you need to have multiple interests for a single user?
If you answered "yes" to both of these questions, then you should leave things the way they are. You'll be able to reuse the same interests entry for multiple users as well as each user being able to have multiple interests.
If you only want one interest per user, but want to keep a "master list" (aka: lookup table) of interests, then you can move the interest_id to the users table.
If you don't care about duplicates, but you still want each user to have multiple interests, move the name column to the users_interests table.
Finally, if you don't care about duplicates and you want each user to have a single interest, move the name column to the users table.
FYI, how you currently have the tables structured will likely take up less disk space for a large amount of users.
It's unclear what you're trying to do, so I included all options. Each option has it's own set of pros and cons, and each will be required of some other project or another at some point. You might want to learn the difference and reasoning behind why you would use one option over another now, so you don't have to think too hard about it later.
You can do it if you will make interests like this
id
user_id
name
but then you will lose uniqness of your interests, you will have many rows with the same name only because they connect to different users. Now db is perfectly ok according my understanding...It is as it should be
Im trying hard to find a way to restrict the access of a user to a particular table. Im working with views now but i cant create what i want...and i dont know if its possible.
Now, what it accomplish was to limit all access to a table..and create a view with the content the user should be able to see...but its not what a want, really.
What i was think:
When i logon with the user XXX, it should be able to visualize the database X_DB...and the table X_TABLE...
BUT when this user selects this table..he only will see the content i defined previously...not the entire content of the table.
I was able to select it into a view..but im cannot make all of it part of one process...
Is that possible?
Thank you
Given that you have 20 databases, one per each client, add your client as a user to just the database you want them to access.
If you want to consolidate all of your databses to a single database, then I suggest that you add "Client" table containing clientId (primary key) and clientName fields, and then modifying the rest of your schema by adding foreign key fields and relationships so that the other data is related to the proper client. Then you can easily provide access to data to clients based on their clientId in conjunction with views and stored procedures.
I am currently refactoring a web-app. Right now there is a 'Contact' table that has a one-to-one correspondence with the main 'Client' table, with a bool indicating if clients want to receive mail. The mail-list is accessed about once per month, and the clients' profile page is accessed many times a day. I am thinking if it would be 'cleaner' to make a new table with the client ids of everyone in the mail-list, as querying if the key is in the table should take about the same time as accessing the information. Should I do that, or should I leave it as it is?
Thanks,
Joyce
Leave it as is. Why complicate? Keep it as simple as possible.
An association table with (clientid, emailid) is too much normalized form. I think its better to keep like this. Also if you want to show contact emailid in any ui screen, you can avoid an inner join overhead due to this new association table.
However in future if you came across a requirement to have multiple emailids associated with a clientid, you could think about creating an association table then.
If you had to design a database with paid users and trial users would you put them in the same table and differentiate between them with a field? Or would you put them in two separate tables?
Or would you do the best of both worlds and put them in the same table but create two views 1) PaidUsers and 2) TrialUsers
Thanks!
I just express some performance considerations in following opinions.
In single user query(ex. login check, or data retrieving for single user), there are not significant differences between these two strategies.
But if you need some statistic data, for example, one for paid users and another for trial users. And seperating to two tables may be a good idea.
Otherwise, if you need some statistic data whatever paid users or trial users, single table may be a good idea.
What if you need both of scenarios? Well, I think that would be a case which some common attributes exist between two kinds of users.
These common attributes should be put in one table, and dedicated attributes for particular users should be put in 'sub-table' inheriting from former table. Just as vonPetrushev said.
Since your paid users would probably be related to some additional data, but still have the same fieldset as non-paid, the correct way to do this is [is-a] approach:
User
id
username
password
fullname
...
Paiduser
user_id [fk->User::id]
account_id
.... [other addidional data]
EDIT: Now, the trial users will be all records in User that does not have entry in Paiduser. I'm assuming that Paiduser fieldset is a superset of the fieldset of a trial/normal user [User].
EDIT 2: To get a list of trial users, which are 'set difference' between User and Paiduser, the following sql should work:
select u.*
from (User as u
join Paiduser as p on u.id<>p.user_id)
The best solution may depend on database type. My experience is with MySQL and SQL Server. I've always put all users into a single table. Then differentiate as needed using fields. This could apply to paid/ unpaid or anything else. This solution meets 3NF standards and seems easier to me for maintenance etc. What reason would there be to use multiple tables?
I am working in a small law firm and my boss has asked me to put a database together to help with outgoing mail. There are 5 different tables that exist in Access. (Applicants, Attorneys, Lien Claimants, Employers and Workers Compensation Boards) All of the tables include addresses only. Each Applicant has an attorney, one or possibly more lien claimants, employer and designated board. I need to create some type of database that will allow me to create a mail merge for all applicants. Keep in mind each applicant has different addresses, employers, etc..(There are roughly 500 applicants) I need to create the database so when I change/update an address on the table in Access it will change ALL of the applicant(s) it pertains to. Tryin to only update a new address in one place instead of 50. If anyone can help please let me know. I am looking for the most efficient and effective way of doing this.
Store the address in one table and then have a join to the other tables so when you update the address it is reflected in all the other places where it is used.
Have a table "addresses" that has an ID in it.
Have the "applicants" table have an ID in it that refers to the ID in the "addresses" table.
Hopefully this is making sense to you. If not add to the comments and I will try to explain in more
detail.
Just to give you some ideas on setting up a database, here is a library of free database models that cover everything from access control to zoo's.
One of the models is for Lawyers, Cases and Bills, while another is for Case Management. All of these examples give you the fields and relationships. Look over these examples and you should be able to see some ideas of how to setup your tables and relationships to solve your problem.
Good luck and hope this helps some.