Is it advisable to have a table of Users relating to others?

2

I am a beginner in systems development, and I wonder if the system user table could establish relationships with other tables, such as the company table.

    
asked by anonymous 02.04.2015 / 17:50

1 answer

3

Yes, no problem.

For example, I could associate users with companies using foreign keys:

CREATE TABLE EMPRESA (
    EMPRESA_ID INT PRIMARY KEY,
    -- Coloque aqui as colunas que você gostaria que EMPRESA tivesse
)

CREATE TABLE USUARIO (
    USUARIO_ID INT PRIMARY KEY,
    EMPRESA_ID INT FOREIGN KEY REFERENCES EMPRESA(EMPRESA_ID),
    NOME VARCHAR(255),
    -- Coloque aqui as colunas que você gostaria que USUARIO tivesse
);

Associations can also be made to other tables. Everything depends on the desired goal.

Note that I did not use a specific SQL syntax. The idea is just to illustrate what can be done.

    
02.04.2015 / 18:05