1

I want to create a trigger on SYS.database_mirroring as it is not a real table, just a view... I can't do it.

I want to know were the field mirroring_state_desc is coming from so that I can create a trigger on that table when it is changed.

How can I know which tables are used to create that view?

1

3 Answers 3

3

Here's a link to an article that shows a few different ways to show VIEW code.

Essentially, you run "exec sp_helptext [view_name]"; obviously exchanging [view_name] with the name of your view.

From with SQL Server Management Studio, you can locate the view in the "views" node, right-click on it, and obtain the code behind it by clicking "CREATE TO" and then a location.

Lastly, you can run the following SQL against INFORMATION_SCHEMA.Views:

SELECT TABLE_NAME as ViewName, VIEW_DEFINITION as ViewDefinition
FROM INFORMATION_SCHEMA.Views

Of course, given the limit of 4000 characters, a better option would be:

SELECT name, object_definition(object_id)
FROM sys.objects
WHERE [type] 'v'
0
6

To take some action when a database mirroring state change occurs, you have several options including WMI and Event Notifications (using the DATABASE_MIRRORING_STATE_CHANGE event):

Altering on Database Mirroring Events

If you are doing any sort of work with mirroring, I can recommend (MVP & MCM) Robert Davis' book:

Pro SQL Server 2008 Mirroring

3

You should use

You don't use

  • INFORMATION_SCHEMA because the VIEW_DEFINITION column is nvarchar(4000) and you may not get all data
  • sp_helptext because you get multiple lines of nvarchar(255)

But you won't be able to set up a trigger on the sys schema

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.