Closed rmantel23 closed 1 month ago
Are you using SQL Server or SQLite? I believe that SQL Server is "smarter" than SQLite and can "reuse" IDs if one is assigned but then the row is deleted before another is added. It all depends on the data provider. The point is, one shouldn't make assuptions about database-assigned values.
This example was with SQLite. I was surprised that it reused the IDs actually. I get the point, and it's valid, but maybe just state more generally that you can't rely on IDs just as you said in your comment.
I've implemented your suggestion for the 9th edition. (This section will be online-only, not in the print book.)
I do not know what the product ID will be for the products that you add. I do know that there are no products that start with “Bob” in the existing Northwind database. Finding a product to update using its name avoids having to tell you to first discover what the product ID is for a product that you’ve added. It is likely to be 78 because there are already 77 products in the table, but once you’ve added that and then deleted it, the next product to be added would be 79 and it all gets out of sync.
Is that correct? I have this:
| 076 | Lakkalikööri | $18.00 | 57 | False | | 077 | Original Frankfurter grüne Soße | $13.00 | 32 | False | | 078 | Bob's Burgers | $500.00 | 72 | False |
Then delete all Bob and have this:
| 076 | Lakkalikööri | $18.00 | 57 | False | | 077 | Original Frankfurter grüne Soße | $13.00 | 32 | False |
Then add Bob again:
| 076 | Lakkalikööri | $18.00 | 57 | False | | 077 | Original Frankfurter grüne Soße | $13.00 | 32 | False | | 078 | Bob's Burgers | $500.00 | 72 | False |
Bob was added again with 78.