I need to add customers, companies and users to a db, I thought to
create a single table with customers and companies named registries
where when I add a user I don't add vat and vice-versa when I add a
company I don't add name and surname!
I need to use a third table for login feature named users but I don't
know if I should link it to the registries!
I thought to add in users table username email and password, I thought
to store all other details in the registries table.
What you'd like to do?
I need to add customers, companies and users to a db, I thought to
create a single table with customers and companies named registries
where when I add a user I don't add vat and vice-versa when I add a
company I don't add name and surname!
Best practice is that you do have the company in it's own table, it will
just be a grouping for users, users will belong to a company or not.
On 25/01/2020 08:54, J.O. Aho wrote:
Best practice is that you do have the company in it's own table, it
will just be a grouping for users, users will belong to a company or not.
Many companies have more than one location.
You need a one to many relationship between the company and 'places'
I need to add customers, companies and users to a db, I thought to
create a single table with customers and companies named registries
where when I add a user I don't add vat and vice-versa when I add a
company I don't add name and surname!
I need to use a third table for login feature named users but I don't
know if I should link it to the registries!
I thought to add in users table username email and password, I thought
to store all other details in the registries table.
What you'd like to do?
^Bart
Best practice is that you do have the company in it's own table, it will
just be a grouping for users, users will belong to a company or not. The
user table can have the credentials, this will allows you to have a
company with multiple users and with different privileges, as the
accountant do not need the privileges to change the content of the pizza while the bake wouldn't need to see the invoices or order extra services.
Say someone would get the credential for one user, they will be able to
do less harm when not having full access to everything and also the
password would be not shared at the company as the account would be
personal. You would also know who has lost it's credentials, which can
help in the investigation how someone got hold of the credentials.
In theory a person could be connected to more than one company, but
seldom happens, so it's up to you if you want a one to one connection
from user to company or an one to multi connection.
Users may have a "admin" flag telling if they have the right to request changes to company user setups.
The company table should of course have all the information for the
company, including an invoice address (email or physical).
Many companies have more than one location.
You need a one to many relationship between the company and 'places'
depends. I wouldnt mix customers and companies.
What I ended up doing was having a 'places' table and a 'people' table
So you could have more than one person in a place. And a place might be
a customer or a supplier or a marekting propsective customer. Etc.
Then using link tables to associate them. So if a place appeared in a
table of customers suppliers and marketing propsects it would mean that
you had bought from a conpany, sold to it and were trying to sell to it.
Customers might also be people who work for companies that supply you,
or indeed they might be companies themselves.
Think carefully about what information is unique to a person and if its
one to one. A person doesnt have several names, but they may have
several phone numbers and several email addresses and they may live in
one place and work in another.
So you may need a one-to-many repalstuonship of people to places and
phone numbers and email addresses
The biggest part of a business analyst trying to model this is software
is to map out and understand these relationships. The next hardest task
is to define the table structires.
The easy part is writing the code to drive the databases
On 25/01/2020 12.22, The Natural Philosopher wrote:
On 25/01/2020 08:54, J.O. Aho wrote:
Best practice is that you do have the company in it's own table, it
will just be a grouping for users, users will belong to a company or
not.
Many companies have more than one location.
You need a one to many relationship between the company and 'places'
A company do just have one HQ, most likely one billing address (sure
some companies may have different departments to pay for their services,
but I doubt that will be the case here), sure a company can have more
than one visiting location, but that you handle in another table.
On 25/01/2020 11:43, J.O. Aho wrote:
On 25/01/2020 12.22, The Natural Philosopher wrote:You may know how to code, but you dont have much experience of
On 25/01/2020 08:54, J.O. Aho wrote:
Best practice is that you do have the company in it's own table, it
will just be a grouping for users, users will belong to a company or
not.
Many companies have more than one location.
You need a one to many relationship between the company and 'places'
A company do just have one HQ, most likely one billing address (sure
some companies may have different departments to pay for their
services, but I doubt that will be the case here), sure a company can
have more than one visiting location, but that you handle in another
table.
multinational companies.
There may be a notional head offioce sited somehere for tax reasons, but
the daughter companies and divisions can be extremely geographically
diverse.
Thank you for your reply! :)
Best practice is that you do have the company in it's own table, it
will just be a grouping for users, users will belong to a company or
not. The user table can have the credentials, this will allows you to
have a company with multiple users and with different privileges, as
the accountant do not need the privileges to change the content of the
pizza while the bake wouldn't need to see the invoices or order extra
services.
Yes this is really true, 99% of users are linked to a company, it could happen to have an user who can be able to see more than a company but it could have a 1% of users who don't have a company (end user!).
Now I should think how many tables I should create, I thought to create:
companies
-----------------------
company_id
name
companyplaces
--------------------------
companyplace_id
placename
placerole ENUM (warehouse, office, warehouseoffice)
company_id_fk
userrules
----------------------------
userrule_id
name (admin, user, superuser)
companies
-----------------------
company_id
name
tax/organization id's? No need to duplicate those.
companyplaces
--------------------------
companyplace_id
placename
placerole ENUM (warehouse, office, warehouseoffice)
company_id_fk
^^^^--- keep the same name on the column as in the table where it's a
primary key.
userrules
----------------------------
userrule_id
name (admin, user, superuser)
You shouldn't make defined roles, you should dived things up in
permissions, say "create recipes", "update recipes", then you have a
roles table with a role name (kind of your userrules) and a join table
where you say what privileges belongs to which role.
You will also need a privileges table where you tell which permissions
(as you may want to give more than just the ones they have for a role)
and last you need a user role table which tells which roles each user has.
This gives you the most flexibility, you can change what an admin can do
or not do without need to recode things, it's just a configuration.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (3 / 13) |
Uptime: | 51:45:14 |
Calls: | 6,650 |
Calls today: | 2 |
Files: | 12,200 |
Messages: | 5,330,383 |