Exforsys

SQL Server 2005 Training

  1. SQL Server 2005 - Configuring Replication
  2. SQL Server 2005 Replication Enhancements
  3. SQL Server 2005 - Mirror Server
  4. SQL Server 2005 - Introduction to Data Availability
  5. SQL Server 2005 - Backing up a Database
  6. SQL Server 2005 - Using Database Snapshots
  7. SQL Server 2005 - Disaster Recovery
  8. SQL Server 2005 - Managing Certificates
  9. SQL Server 2005 - Managing Permissions
  10. Managing SQL Server 2005 Security
  11. SQL Server 2005 - Using the Database Tuning Advisor
  12. SQL Server 2005 - Tuning a Database
  13. Maintain indexes in a SQL Server 2005 database
  14. SQL Server 2005 - Defining Indexes
  15. SQL Server 2005 - Database Backup
  16. SQL Server 2005 - Populating the Database
  17. SQL Server 2005 Configuration Manager
  18. SQL Server 2005 - Using the Sqlcmd Utility
  19. Using the SQL Management Objects
  20. Using SQL Sever Management Studio - Part 2
  21. Using SQL Sever Management Studio - Part 1
  22. SQL Server 2005 - Using Event Notifications
  23. SQL Server 2005 - Using DDL Triggers
  24. SQL Server Monitoring Tools - Server Profiler
  25. SQL Server 2005 - Testing Troubleshooting
  26. SQL Server 2005 - Upgrading from earlier versions of SQL Server
  27. SQL Server 2005 Installation - Maintenance Plan Without Using Wizard
  28. SQL Server 2005 - Unattended Installations
  29. SQL Server 2005 Installation - Maintenance Plan Using Wizard
  30. Installing a Second Copy of SQL Server 2005
  31. Planning to Install SQL Server 2005
  32. SQL Server 2005 Installation
  33. SQL server 2005 Editions
  34. SQL Server 2005 Architecture Overview
  35. SQL Server 2005 - Management studio interface Summary Page
  36. SQL Server 2005 - Server Groups
  37. SQL Server 2005 - Registered Servers
  38. SQL Server 2005 Administrative Tools
  39. Developing Client applications in SQL Server 2005
  40. SQL Server Management Objects
  41. NET CLR in SQL Server 2005
  42. Native HTTP Support in SQL Server 2005
  43. XML Data Types in SQL Server 2005
  44. Using XML in SQL Server 2005
  45. Using Notification Services in SQL Server 2005
  46. SQL Server 2005 - Service Broker
  47. Data Manipulation Language (DML) in SQL Server 2005
  48. T-SQL Enhancements in SQL Server 2005
  49. Security Features in SQL Server 2005 for the Developer
  50. SQL Server Architecture and Components
  51. SQL Server 2005 Management Studio
  52. Overview of SQL Server 2005 for the Database Developer
  53. Getting started with SQL Server 2005

Ads


Home arrow Technical Training arrow SQL Server 2005 Training

SQL Server 2005 - Using Event Notifications

Author : Exforsys Inc.     Published on: 13th Dec 2005

SQL Server 2005 - Using Event Notifications

In this tutorial you will learn about SQL Server 2005 - Using Event Notifications, Creating Event Notifications, Creating an Event Notification, Creating the Target Service, Creating /Dropping / modifying the Event Notification and Using Metadata Views.

Ads

DDL statements or SQL Trace events execute Event Notifications. The information is sent to a Service Broker Service. These event notifications help in logging and reviewing changes occurring in databases. They perform action in response to an event in an asynchronous manner. They can be said to offer a programming alternative to DDL triggers and SQL Trace.

Event notifications can be used inside database applications to respond to events, operating outside the scope of the transaction. In this Event notification are different from DDL triggers.

Event notifications perform actions inside an SQL Server in response to a SQL Trace Event. In this they are different from SQL Trace.

Event notifications open one or more Service Broker conversations between the SQL Server and the target service. These conversations also continue so long as the event notification exists as an object in the server instance and are never shared between event notifications. The target service will cease to receive messages when the event notification ends and the target service will not be opened the next time the event notification is fired.

The variable type xml is used to deliver Event information to the Service Broker. The information specifies the details of the event, the database object impacted, the T-SQL statement and other required information.

Creating Event Notifications

While designing event notifications it is important for the DBA to define the scope of the notification and the type of T-SQL statement(s) that will fire the notification.

The event notification can be defined to respond to a statement made on the objects in a database or on all object on an instance of the SQL Server. Event notifications that can be scoped on individual queues are QUEUE_ACTIVATION and BROKER_QUEUE_DISABLED. CREATE _DATABASE events run only on server instance level while ALTER_TABLE event can run on all tables in the database.

An event notification can be designed to fire after a particular Transact-SQL statement is run or after a SQL Trace event belonging to a predefined grouping of similar trace events is run.

Creating an Event Notification:

An event notification involves creation of a target service to the event notification and the process of creating the event notification.

Creating the Target Service

1. Create a queue to receive messages.
2. Create a service on the queue that references the event notifications contract.
3. Create a route on the service to define the address to which Service Broker sends messages for the service. If the event notification targets a service in the same database, the DBA must specify ADDRESS = 'LOCAL'.

CREATE QUEUE ExforsysQueue ;
GO
CREATE SERVICE ExforsysService
ON QUEUE ExforsysQueue
(
[http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]
);
GO
CREATE ROUTE ExforsysRoute
WITH SERVICE_NAME = 'ExforsysService',
ADDRESS = 'LOCAL';
GO

Creating /Dropping / modifying the Event Notification

Transact-SQL CREATE EVENT NOTIFICATION statement is used for creating Event notifications. The Event notification can be dropped using the DROP EVENT NOTIFICATION STATEMENT. It can be modified by dropping and recreating it only.

Event notifications can be created on remote servers by defining routes on both the source and the target server for two way communication. It is necessary to enable the two instances of SQL Server to connect to each other by creating Service Broker end points on both instances.

Using Metadata Views

Information about views can be derived if the view is not encrypted. Views can be queried in the same way that tables are queried. However, any table hints will be ignored. Changing the name of the object referenced in a view will require a modification of the view to make the text reflect the new name. To get information about a view the following statements can be used.

sys.views (Transact-SQL)

sys.columns (Transact-SQL)

sp_helptext (Transact-SQL)

To view the data defined by a view

SELECT (Transact-SQL)

To display the dependencies of a view

sys.sql_dependencies (Transact-SQL)

Metadata of views can also be obtained by using Information Schema views. These views can be used to garner information regarding internal, system-table independent view of the SQL Server metadata. These views allow applications to work properly despite changes being made to the system tables. They conform to the SQL 92 standard definition for the INFORMATION_SCHEMA.

The SQL -92 standard supports three part naming convention just like SQL Server. However the naming convention in SQL Server 2005 is slightly different from SQL 92 and are defined in as special schema called INFORMATION_SCHEMA which contains metadata for all data objects stored in the database.

Ads

Some views contain references to different classes of data which include character data and binary data. The syntax for viewing metadata on views is as under:

SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT
FROM Exforsys.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'Product';
GO

In this lesson we have examined in detail the monitoring tools of SQL Server 2005. In the lessons that follow we shall see how the DBA can maintain databases and indexes.



 
This tutorial is part of a SQL Server 2005 Training tutorial series. Read it from the beginning and learn yourself.

SQL Server 2005 Training

  1. SQL Server 2005 - Configuring Replication
  2. SQL Server 2005 Replication Enhancements
  3. SQL Server 2005 - Mirror Server
  4. SQL Server 2005 - Introduction to Data Availability
  5. SQL Server 2005 - Backing up a Database
  6. SQL Server 2005 - Using Database Snapshots
  7. SQL Server 2005 - Disaster Recovery
  8. SQL Server 2005 - Managing Certificates
  9. SQL Server 2005 - Managing Permissions
  10. Managing SQL Server 2005 Security
  11. SQL Server 2005 - Using the Database Tuning Advisor
  12. SQL Server 2005 - Tuning a Database
  13. Maintain indexes in a SQL Server 2005 database
  14. SQL Server 2005 - Defining Indexes
  15. SQL Server 2005 - Database Backup
  16. SQL Server 2005 - Populating the Database
  17. SQL Server 2005 Configuration Manager
  18. SQL Server 2005 - Using the Sqlcmd Utility
  19. Using the SQL Management Objects
  20. Using SQL Sever Management Studio - Part 2
  21. Using SQL Sever Management Studio - Part 1
  22. SQL Server 2005 - Using Event Notifications
  23. SQL Server 2005 - Using DDL Triggers
  24. SQL Server Monitoring Tools - Server Profiler
  25. SQL Server 2005 - Testing Troubleshooting
  26. SQL Server 2005 - Upgrading from earlier versions of SQL Server
  27. SQL Server 2005 Installation - Maintenance Plan Without Using Wizard
  28. SQL Server 2005 - Unattended Installations
  29. SQL Server 2005 Installation - Maintenance Plan Using Wizard
  30. Installing a Second Copy of SQL Server 2005
  31. Planning to Install SQL Server 2005
  32. SQL Server 2005 Installation
  33. SQL server 2005 Editions
  34. SQL Server 2005 Architecture Overview
  35. SQL Server 2005 - Management studio interface Summary Page
  36. SQL Server 2005 - Server Groups
  37. SQL Server 2005 - Registered Servers
  38. SQL Server 2005 Administrative Tools
  39. Developing Client applications in SQL Server 2005
  40. SQL Server Management Objects
  41. NET CLR in SQL Server 2005
  42. Native HTTP Support in SQL Server 2005
  43. XML Data Types in SQL Server 2005
  44. Using XML in SQL Server 2005
  45. Using Notification Services in SQL Server 2005
  46. SQL Server 2005 - Service Broker
  47. Data Manipulation Language (DML) in SQL Server 2005
  48. T-SQL Enhancements in SQL Server 2005
  49. Security Features in SQL Server 2005 for the Developer
  50. SQL Server Architecture and Components
  51. SQL Server 2005 Management Studio
  52. Overview of SQL Server 2005 for the Database Developer
  53. Getting started with SQL Server 2005
 

Comments