![]() There is a link to the SQLite website at the end of this blog where foreign keys are discussed at length. Note there is much more to foreign keys than in my explanation above, but this is sufficient to understand the main points of this blog. When they exist, they, therefore, provide a useful clue to help us understand the relationships between tables. In the example above trying to add a new message with a userID that does not exist in the users table will fail, likewise attempting to delete a user when there is a message that refers to that userID will also fail. For example, in the case of a simple messaging database, they can ensure that for every message with a userID there is an entry for the userID in the user’s table.įOREIGN KEY (userID) REFERENCES users(userID) Simply put, foreign keys provide a way of ensuring that relationships between tables are valid. This example is, of course, a little contrived but it should, I hope, show the principles well. To help with this let’s assume I have been asked to investigate file transfers between the user of this DB and his/her contacts and create a simple report to detail the transfers. ![]() The particular feature that I want to discuss in this blog is foreign keys, and I intend to show their value by example, as if I have just been asked to create a report on a database (BlackBerry Messenger master.db from an IOS device) of which I have little knowledge. SQL is an extremely powerful programming language, and understanding SQL database schemas can often help immensely when creating queries on the database in question.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |