0

I am trying to make online examination system. I have three tables. Table "student" has details of students, column id identifies students uniquely. Table "tests" has details of all the tests available and there is a column id which contains id of tests. and then I have tables of tests which contains questions and answers.

Now I want that if any student has appeared in a test, it can not reappear in that test again. How can I achieve that? Please help. Thanks in advance.

1 Answers1

0

Aah. If you need to create the relation table... First make a table relating the student_id and the test_id. When you make this you can make the primary key on multiple columns:

CREATE TABLE students_tests
( 
FOREIGN KEY student_id REFERENCES student(id) ,
FOREIGN KEY test_id REFERENCES tests(id)
PRIMARY KEY (student_id,test_id)
)

However, if you already have the relation table with a primary key, you can make pairs (or tuples) of keys a unique set with the ALTER TABLE ... ADD UNIQUE command . This question has been answered here:

How do I specify unique constraint for multiple columns in MySQL?

Community
  • 1
  • 1
Billyziege
  • 56
  • 6