When I use the following SQL Server command to add foreign key
ALTER TABLE [TABLE_A]
WITH CHECK ADD CONSTRAINT [FK_TABLE_A_TABLE_B]
FOREIGN KEY ([COLUMN_A]) REFERENCES [TABLE_B] ([COLUMN_A])
it will run very slow on tables with large size. Is there any faster/optimized way to add foreign key on table with large size?
Thanks!
There is no online way to add a foreign key but you can do two things to make it faster:
select count(*) from TABLE_A with (index(IX_TABLE_A_COLUMN_A)).That reduces the time it takes to build a (trusted) foreign key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With