Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Instead of Update trigger
Message
From
09/08/2011 04:45:58
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
01520382
Message ID:
01520480
Views:
39
>>>>>>>I am now thinking of doing away with the SQL Server triggers and do the cascading updates and deletes in the VFP application.
>>>>>>
>>>>>>(1) Would we be programmers if we were to quit ?
>>>>>>(2) There must be a way
>>>>>
>>>>>(1) Gracias por animarme.
>>>>>(2) So far the only solution way I found is to implement a Delete trigger so that my child foreign keys would be set to empty string (''). And to use foreign key constraint (in SQL Server) to do Cascading update. This seems to work for 90% of the tables (guesstimate). Except that (as I posted in the past) SQL Server does not allow for setting up some foreign key constraint cascade. For those few cases I will need to find a solution.
>>>>
>>>>
>>>>None of my business, but I've never had a situation - and I cannot think of one - where I had to do that (child foreign keys would be set to empty string )
>>>>
>>>>Also, do you have a char field as a key ?
>>>
>>>What about Re: Having a row with empty unique field? Thread #1520263 Message #1520278?
>>>
>>>Yes, the char field is the unique key field in one table. And this key field has foreign keys in child tables (note that these are not primary keys, just unique key in one table and foreign key in another). When user deletes a record in the unique key table I need to set the foreign keys (in child tables) to empty string (not NULL).
>>
>>
>>Yes, I remember that message - thought it was about primary keys
>>
>>Just cannot grasp it
>>
>>(1) Why would you store a unique key in child tables instead of a primary key ?
>>
>>(2) >When user deletes a record in the unique key table I need to set the foreign keys (in child tables) to empty string
>>
>>Sounds a bit strange to me. It is as if when deleting a customer, you change the customer's reference to empty in all the orders of the customer
>
>Let me give you an example. User creates a purchase order. One of the fields of the purchase order is a cost center (an account) to which P.O. could be optionally charged. Each cost center is a unique field in the Cost Center table. The P.O. table has Cost Center foreign key. This Cost Center is a char field. If user enters a Cost Center in the P.O., everything is well. But when user clears (removes) entry from the P.O. table (because he/she decide that they do not want to charge the P.O. to a cost center), I want the Cost Center in the P.O. table to be empty string (not NULL).
>Also when user deletes a Cost Center from the Cost Center table, after a warning, the foreign key in all P.O.s where the deleted Cost Center was used should be either set to NULL or empty string. I need/prefer that it is set to empty string. This is why I needed to have record in the Cost Center table with empty value in the Cost Center field.
>
>Does it all make sense?

No.

SQL Server is designed to NULL

So I suggest you use a ForeignKey rule that set null or sends the change in values ​​in the child table,

If you need empty in VFP, uses ISNULL(field,'') on the query.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform