Is there any way to automatically validate system triggers to see if I have broken any by renaming columns in foreign keys? It upset me to discover whilst investigating a bug today the following statement in the docs, which I was not aware of previously:
Hopefully I haven't done this in too many places, but hunting through every system trigger doesn't fill me with excitement ... As a sidenote - why does it not just prevent you from renaming columns in foreign keys as it does with primary keys? EDIT: This is using 11.0.1.2352. It definitely doesn't seem to be correcting the system triggers automatically on rename! EDIT to provide an example as requested: Create a DB (using Sybase Central wizard defaults):
Then run the following SQL statement:
Oddly, what then appears to happen is that the update columns system trigger is deleted. The delete trigger remains but with the wrong key name (as the docs suggest should happen). This is with 11.0.1.2427. asked 15 Dec '10, 14:55 Adam King |
Starting with 10.0.1, the server will automatically correct system triggers when a column in a primary key or foreign key is renamed. Update: Thanks for the example. Looks to be a bug that affects ON UPDATE as well as foreign keys that specify both ON UPDATE and ON DELETE. To detect any problems, you can execute:
to copy the schema (no data) and generate correct triggers. Then execute:
on both the original and new databases (changing the output filename). Then diff the files. Unfortunately, this will not detect those triggers that have been deleted. If you have a backup from before the columns were renamed, you could perform the same process using that copy of the database. This problem has been fixed in:
answered 15 Dec '10, 16:43 Bruce Hay This doesn't appear to be the case to me using 11.0.1 Please provide an example that shows the problem. 1
Edited to provide example, but are you saying the docs are wrong on this? Whether or not the problem is a bug or by design, is there any way I can test all the system triggers which exist in my DB to ensure there aren't any which are broken? Thanks Bruce - this helped find the issues. There were only a couple in the end thankfully. |