Home > other >  Question on maximum foreign key references in SQL server [closed]
Question on maximum foreign key references in SQL server [closed]

Time:09-28

I am quite new to SQL and coding in general. I recently found out that a table can reference a maximum of 253 other tables and columns as foreign keys. This caused me to be concerned because I currently have two tables, Orders and Order Details.

Orders table

Order# Total DateTime PaymentMethod Cashier
2203 7.49 2021-09-22 10:31:50.560 Cash Jimmy

Order Details Table

ID Order# Item QTY Price
10 2203 Hotdog 2 2.30
11 2203 Cookie 1 0.99
12 2203 BEANS 3 4.20

In the Orders Table, Order# is the primary key. In the Order Details Table, Order# is the foreign key.

Will having foreign key cause an error once I reach 253 Orders? If that's the case, would removing the foreign key be the remedy? If not, I guess I'm just having issues understanding what they mean by maximum referenfce of 253 foreign keys.

CodePudding user response:

No, it will not error when you have 253 orders. The 253 orders you mentioned are number of records (rows) in the table. You can as many records as you can in that table as your identity column allows or your server storage allows.

The 253 foreign key limit in a table means that only 253 separate columns in a table can have foreign key reference to another table. If you reach that amount of foreign keys, then the database and table is badly written/structured as the more foreign keys you have, the more foreign keys you have, the more performance issue you get.

  • Related