daphsta
daphsta

Reputation: 25

Adding foreign key constraint in table vs Alter table adding foreign key constraint

I have a newbie question here in terms of database design and I've noticed 2 options. 1) include the foreign key constrain in the create table block 2) create table then Alter table by ADD CONSTRAINT FOREIGN KEY

Appreciate your experienced view on this

Upvotes: 0

Views: 489

Answers (1)

Vishwanath Dalvi
Vishwanath Dalvi

Reputation: 36621

1. include the foreign key constrain in the create table block

self explanatory, You're creating foreign key constraint in create table there are not records.

2) create table then Alter table by ADD CONSTRAINT FOREIGN KEY

If you don't have any records in table then this will behave as 1. If you've any records in tables then you need to take care whether the available records doesn't violates the foreign key constraints.

Upvotes: 1

Related Questions