This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I have the following fields "time_slot", "weekdays" and "room_number" in a table called "modules". I am trying to check for the following constraint before inserting a new record into the table. . If a record already exists with a "time_slot" on a specifc "weekday" within a specific "room_number" than do not save a new rcord (this is multiple of the record already in the db).
If there exists a record in the table with time_slot = "9:00", Weekday="Monday", Room_Number="F123" ... then another record cannot exist under these constraints i.e a duplicate record cannot be created with these values time_slot = "9:00", Weekday="Monday", Room_Number="F123" ...
Here is the Insert code I guess I need a way to check if there already exists a record that has the above constraint before executing the following code. Can someone please show me an example of how to do this?
Tim, There are two possible approaches: 1) Do a select before the insert to see if it already exists - with this approach you need a transaction so two inserts don't occur simultaneously. 2) Enable a database constraint and catch the exception as a duplicate.