Khush Ina
Khush Ina

Reputation: 11

Two foreign key referencing to same primary key being used as a composite key[ERD]

I want to draw an ERD, showing the relationship between two tables. Below are their sql queries.

CREATE TABLLE USERS(userid INT PRIMARY KEY, name VARCAHR(20));

CREATE TABLE RATING(userid INT REFERENCES USERS(userid), userid2 INT REFERENCES USERS(userid), number int, PRIMARY KEY(userid, userid2));

Upvotes: 1

Views: 63

Answers (1)

Prahalad Gaggar
Prahalad Gaggar

Reputation: 11609

Find the screen shot of your ER Diagram:

ER Digram

Some more information/tips:

I am not sure, which RDMS you are using, but if you have access to SQL Server Management studio an ER diagram can be created quickly by below steps:

  1. Go to Sql Server Management Studio >
  2. Object Explorer >
  3. Databases >
  4. Choose and expand your Database.
  5. Under your database right click on "Database Diagrams" and select "New
  6. Database Diagram".
  7. It will a open a new window. ...
  8. Select the tables "Users" and "Rating" Click add (1 time for each table). Then click close
  9. Wait for it to complete.

Upvotes: 1

Related Questions