Sunday, February 12, 2012

Constraing Question

Converting a program from VS03/MSDE to VS05 Pro/SQL Express...

In VS05, in Datasouse tab, "edit with Dataset with designer", click on relation between two tables, choose "edit relation" from context menu, under "Choose what to create" there are 3 radio buttons:

- Both relation of foreign key constraint

- Foregin Key constraint only

- Relation only

I have discovered that the choice made dramatically affects the Fill order of tables. In general I use the first one.

I would like more information on these options than I have been able to find in help.

Here is the specific issue (simplified)...two tables UserID -> Recordings. In a specific senerio, I must fill recordings table first, and use the Foreign Key to back track to get the UserID and fill the UserID table, which means for the Recordings table I use the radio button Relation only (otherwise I get a constraint error)

Would it be better to use the first radio button, "Both relation of foreign key constraint", but relax constraints when filling Recordings/UserID tables, and then enfore constraints again when done? Which is the better way?

Thanks for your help

Bob

hi Bob,

selecting the 1st radio performs both a database relation and an application code relation...

the 1st one is an actual object in the underlying database, a constraint object of foreign key..

the 2nd one only is a "soft" relation, an object not present in the database as a real constraint, but residing "in memory" in the actual "in memory database" represented by the dataset, which should be performed after the "fill" has been finished validating (if accordingly set) eventual constraints... but this only client side, in the "in memory database"...

obviously, better protection is set when the actual constraint is defined in the database as this is the place of the real "storage", where data should alway be "correct" and consistent...

as you are loading data from a "protected" source, the database with enforced fk constraint, it's a good idea to relax constraints when filling, as you already know they would be satisifed and enforced by the underlying datasource, so you can improve performance enforcing .Net relation's constraints after the initial filling, to protect application code in the disconnected scenario we all are working.. this way, erratic handling would be reported immidiatly without having to wait for the "sync" roundtrip to the actual datasource...

regards

No comments:

Post a Comment