Say I have a database looking like this;
Product with columns [ProductName] [Price] [Misc] [Etc]
Order with columns [OrderID] [ProductName] [Quantity] [Misc] [Etc]
ProductName is primary key of Product, of some string type and unique.
OrderID is primary key and of some integer type, and ProductName being a foreign key.
Say I change the primary key of Product to a new column of integer type ie [ProductID]
.
Would this reduce the database size and optimize lookups joining these two tables (and likewise operations), or are these optimizations performed automatically by (most/general/main) SQL database implementations?
Technically, using (String) ProductName as primary key in Product
, a database should be able to implement the ProductName column in Order
as simply a pointer to a row in Product
, and perform a JOIN
as quicly as having an integer as a foreign key, is this a standard way of implementing SQL.
Update: This question is about how SQL servers handles foreign keys, not whether a product table needs a serial number, or how I handle to product name change in a database.