<p>I'm primarily interested in pgsql for this, but I was wondering if there is a way in any RDBMS to do an insert operation, <em>without</em> disabling and re-enabling any FOREIGN KEY or NOT NULL constraints, on two tables that refer to each other.  (You might think of this as a chicken that was somehow born from its own egg.)</p>

<p>For a practical example, if you had a multiple-choice quiz system, with tables "question" and "answer", where question.correct_answer refers to answer.id, and answer.question refers to question.id, is it possible to add a question and its answers simultaneously?</p>

<p>(For the record, I'm aware that you can do the disabling and re-enabling in a transaction block, and that another solution is to not have a correct_answer column but instead have answer.correct as a boolean and have a check constraint making sure there's exactly one correct answer per question.  But I'm not curious about alternative solutions here.)</p>

I think that you answered your own question - you have to make a transaction block. In PostgreSQL this should work:
```
```
BEGIN;
  SET CONSTRAINTS ALL DEFERRED;
INSERT INTO questions (questionid, answerid, question)
  VALUES (1, 100, 'How long are Abraham Lincoln\'s legs?');
INSERT INTO answers (answerid, questionid, answer)
  VALUES (100, 1, 'Long enough to reach the ground.');
COMMIT;
```
```
It has to be in a transaction block because if either INSERT statement failed the database would be in an invalid state (table constraints not met).