
It’s a documented bug in SQL server that causes above error message. The error is triggered by nested comment blocks, like this example:
/*
some comments
/* nested comments*/
some more comments
*/
All very well, it’s a documented bug so it shouldn’t be a problem. Microsoft’s solution is plain and effective: don’t use nested comment blocks.
But what if, like in my case, you created the trigger using SQL server 2000′s Enterprise Manager (which does not suffer from the bug) and you’re trying to open the trigger much later using Microsoft’s SQL Server Management Studio? The trigger will fail to open and you’re pretty well stuck.
What is needed now is a way to get to the trigger without opening it directly in the Management Studio. Luckily SQL Server stores all its tables, views, stored procedures and triggers in the database itself. So to get to the trigger we need to know where it is stored.
In this post I described how to display a list of tables, views or other user objects from SQL Server. If we expand the query a little it allows us to get to the contents of the trigger we need:
SELECT o.[name], c.[text]
FROM sysobjects o INNER JOIN
syscomments c ON o.ID=c.ID
WHERE o.xtype = 'TR'
As you can see the contents of triggers is stored in the SYSCOMMENTS table. Note that longer functions, triggers and stored procedures may have multiple entries with the same name in SYSCOMMENTS. You may have to concatenate the text fields of multiple records together to get the complete contents of your function. I found the best way is create a small loop and PRINT the results instead of outputting them to the default grid.