Ensuring relationship between child tables exists prior to SQL insert
Recommended scheme:
Existing tables (PK == Primary key):
user (user_id PK, etc.)
assignment (assignment_id PK, etc.) 
test (test_id PK, etc.)

Relations tables (PK == Primary key, FK == Foreign key):
user_assignment (user_assignment_id PK, user_id FK, assignment_id FK, etc.)

This table creates the relation &quot;user to assignment&quot; which would check to see if the user and assignment exist.
user_test (user_test_id PK, user_assignment_id FK, test_id FK, etc.)

This table creates the relation &quot;user with existing assignment to test&quot;.