Create Mysql Ddl (schema)

Create Mysql Ddl (schema)
I need a mysql schema created.

with some example (left join) queries to retrieve information.
Should be easy stuff.

I currently
got the following tabels.

companies
company address
users

both company address and users tabel have a foreinkey on the companies.company_id

Now I need to know how to setup the following.
I need to know who the owner is (company_admin) for that company.
so i created a table column “owner” in the companies table, and put the users.user_id in there.

I don’t think that is a good design.
because today we realized that some companies should be able to create branch offices.
not all branch offices will use there own company_admin to add users to there office.
The parent office/company owner (company_admin), will create users for the branch office.
But we still need to know who to contact from the branch office.

The company_admin is the person we will contact.
so 2 things can happen. The company_admin will always be responsible for the main office
if there are branch offices, the same company_admin could be the contact, or he could assign
a new users beloning to that branch office as the company_admin for that office.

How should we store branch offices?
how do we know which branch office, belongs to which company?
also how do we assign a company_admin.

I need a database ddl for this (mysql preferred, but the logic behind it is owke to i will be able to convert it to mysql)
and need to know the logic. (if I know the logic, i can create the sql for it, but sample queries would be nice)

Leave a Reply

Your email address will not be published. Required fields are marked *