all groups > sql server new users > october 2006 >
You're in the

sql server new users

group:

Problem with Script



Problem with Script Vayse
10/27/2006 3:27:09 PM
sql server new users: Hi
I ran this script to make all my ClientIDs uppercase.
UPDATE Clients SET Clients.ClientID = Upper([ClientID])

After it ran, all linked tables had the one ClientID - ZHIR01, which is the
last ClientID.
The relationships were set to Cascade Update and Delete.
Why would this happen?
Thanks
Vayse

Re: Problem with Script Hugo Kornelis
10/29/2006 12:21:35 AM
[quoted text, click to view]

Hi Vayse,

My first guess is that yoou are bitten by a badly coded trigger.

Please check if there's an UPDATE trigger defined for the table. If so,
post the trigger's code here.

It would also help if you post the table's structure as a CREATE TABLE
statement. Make sure to include all properties, constraints, and
indexes!

--
Re: Problem with Script Vayse
10/31/2006 12:00:00 AM
And indeed it looks like your guess is correct. I won't post the create
table statement here, mostly because it is just too long, as there around
150 fields in it. (which I intend to change)
On the clients table, there are 3 triggers - one each for Insert, Delete and
Update.
Here is part of the Clients_UTrig, the rest of the trigger is just the same
code but for different tables.

/* * CASCADE UPDATES TO 'Submissions' */
IF UPDATE(ClientID)
BEGIN
UPDATE Submissions
SET Submissions.ClientID = inserted.ClientID
FROM Submissions, deleted, inserted
WHERE deleted.ClientID = Submissions.ClientID
END

I've inherited this database, and didn't realise the triggers were there.
Though I should have checked!
Anyway, this raises an interesting question for me. As I mentioned in the
original post, there are relationships set up.
Wouldn't the relationship take care of the update and delete? I think I can
delete these triggers.

Thanks
Vayse


[quoted text, click to view]

Re: Problem with Script Arnie Rowland
10/31/2006 9:22:39 AM
By itself, the relationship will not do what you desire. You will need to
add CASCADE UPDATE and/or CASCADE DELETE to the foreign key constraint.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]

Re: Problem with Script Arnie Rowland
11/1/2006 3:15:46 PM
We are together on this, and it sounds like you have set the constraints up
the way you had hoped.

By checking the checkboxes in the GUI, you are adding the CASCADE UPDATE
and/or CASCADE DELETE to the constraint.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]

Re: Problem with Script Vayse
11/1/2006 10:59:30 PM
I'm a bit confused. Doesn't ticking the Cascade Update and Cascade Delete in
the Database Diagram set those values in the constraint?

[quoted text, click to view]

Re: Problem with Script Vayse
11/2/2006 10:17:32 PM
Thanks!
[quoted text, click to view]

Re: Problem with Script Vayse
11/2/2006 10:17:32 PM
Thanks!
[quoted text, click to view]

AddThis Social Bookmark Button