Bill Wehnert (5/18/2012)
I think the assumption in the example is that all fields are being created as NOT NULL by default.
Table 3 doesn't get created because there is no PK defined on Table2, you can't reference another table without their being a PK.
Making the assumption we have non-nullable fields, we can say that Table1 was created and Table2 was created allowing the reference to be established. So the answer had to be two tables.
The code for table one takes care of the NOT NULL with the Primary Key directive.
CREATE TABLE Table1(
id_tbl INT Primary Key,
When you use Primary Key with no other qualifiers in a create table statement several things happen.
1. The column is immediately flagged as NOT NULL
2. A Clustered Index is created on the column
3. The column is the Primary key of the table.
Been that way since SQL 7, when I started with SQL.