tabla1 --------tabla1-tabla2----------tabla2
Código
CREATE TABLE article ( id BIGINT PRIMARY KEY, title text NOT NULL, score INT NOT NULL ); CREATE TABLE tag ( id BIGINT PRIMARY KEY, name text NOT NULL ); CREATE TABLE article_tag ( article_id BIGINT NOT NULL REFERENCES article (id), tag_id BIGINT NOT NULL REFERENCES tag (id), PRIMARY KEY (article_id, tag_id) );
o ...
Código
CREATE TABLE article ( id BIGINT PRIMARY KEY, title text NOT NULL, score INT NOT NULL ); CREATE TABLE tag ( id BIGINT PRIMARY KEY, name text NOT NULL ); CREATE TABLE article_tag ( article_id BIGINT NOT NULL, tag_id BIGINT NOT NULL, PRIMARY KEY (article_id, tag_id), FOREIGN KEY(article_id) REFERENCES article(id), FOREIGN KEY(tag_id) REFERENCES tag(id) );
tambien como me puedo dar cuenta que estan relacionadas