1
I’m doing a tcc project, which is kind of a social network..., I want to create a followers system but I don’t know how to put this in the database or how to relate the data I already have
this and the user table
CREATE TABLE usuario(
id_usuario SMALLINT AUTO_INCREMENT,
nome VARCHAR (50) NOT NULL,
sobrenome VARCHAR (50) NOT NULL,
apelido VARCHAR (25) NOT NULL,
email VARCHAR (60) NOT NULL,
senha VARCHAR (15) NOT NULL,
numero VARCHAR (11),
id_status VARCHAR(4),
data_nascimento DATE NOT NULL,
cpf VARCHAR (11),
CONSTRAINT pk_id_usuario PRIMARY KEY (id_usuario),
CONSTRAINT fk_id_status FOREIGN KEY (id_status) REFERENCES status (id_status)
);
and this is the artist’s table
CREATE TABLE artista(
id_artista SMALLINT AUTO_INCREMENT,
descricao VARCHAR(200) NOT NULL,
id_usuario SMALLINT NOT NULL,
-- seguidores INT, --
rede_social VARCHAR(200),
CONSTRAINT pk_id_artista PRIMARY KEY (id_artista),
CONSTRAINT fk_id_usuario_artista FOREIGN KEY (id_usuario) REFERENCES usuario (id_usuario)
);
I don’t know how to make such a relationship since the artist is also a user.
I would store AB and BA. A 'friendship' is really a two-way relationship, each entity is linked to another. Although we intuitively think of "friendship" as a link between two people, from a relational point of view, it’s more like "A has a friend B" and "B has a friend A". Two relationships, two records.
– Azzi - Digicard