0

I have followed following steps:

  1. Created Two Tables (No Constraint)
  2. Alter Table#1 (Add Not Null and Primary Key Constraint)
  3. Alter Table#2 (Add Foreign Key Constraint) . . And now Trying to Add Primary Key Constraint to Column which is Foreign Key for the Table#2

Got the Error like column can not be NULL.

1 Answers1

0

It good practice for a foreign key to reference a primary key. You are getting this error because a primary key can't be set on a nullable column. Can you change the primary key to be an identity column ?

Alex
  • 21,273
  • 10
  • 61
  • 73
  • thank you for your reply, but what makes foreign key to be null by default? as with my question i need to set not null constraint for my foreign key also. – Ankit Jabavani Apr 01 '15 at 09:50
  • One of the columns referenced by the foreign key is defined as NOT NULL. You need to change the column definition to NOT NULL. – Alex Apr 01 '15 at 10:04