trigger und event notifications im sql server 2005 artus krohn-grimberghe ehem. student partner...

29
Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program [email protected]

Upload: carlene-reichling

Post on 05-Apr-2015

112 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Trigger und Event Notifications imSQL Server 2005

Artus Krohn-GrimbergheEhem. Student PartnerMicrosoft Student [email protected]

Page 2: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Microsoft SQL Server 2005 Architektur

Komponenten des SQL Server 2005

RDBMSETL WerkzeugOLAP ServerData MiningReporting-DiensteManagement-ToolsEntwicklungs-Tools

Analysis ServicesOLAP & Data Mining

Integration ServicesETL

SQL ServerRelational Engine

Reporting Services

Managem

ent ToolsDev

elop

men

t Too

ls

Page 3: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Agenda

Aktive KomponentenDML- und DDL-TriggerEvent NotificationsAusblick SQL Server 2008

Page 4: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Aktive Komponenten

SQL Server AgentJobs (Automatisierung)Alerts (Ereignis und Aktion)

TriggerEvent NotificationsDeclarative Management Framework (ab „Katmai“)

Page 5: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Agenda

Aktive KomponentenDML- und DDL-TriggerEvent NotificationsAusblick SQL Server 2008

Page 6: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

DML- und DDL-Trigger

Prozeduren, die bei Datenbankereignissen automatisch ausgeführt werdenLaufen im Kontext des Auslösers ab (sind Teil der Transaktion, die sie ausgelöst hat)Können den Auslöser zurückrollen Werden nur einmal pro Befehl ausgeführt

DML- und DDL- / LOGON-TriggerAFTER- und INSTEAD OF-TriggerT-SQL- und .NET-Trigger

Page 7: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Ausführung im Kontext

Zurückrollen der Transaktion möglichBeim Zurückrollen entstehen doppelte Kosten, daher n.M. constraints (Datentyp, CHECK, DEFAULT, PK, FK, DRI) benutzenBerechtigungskontext beachten!

CREATE TRIGGER trg1 ON dbo.tbl1 AFTER INSERT ASIF EXISTS(SELECT * FROM inserted WHERE col1 = <some_value>) ROLLBACK TRANSACTION

Page 8: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Verschachtelung und Rekursion

Trigger können standardmäßig andere Trigger auslösenTrigger können sich selbst aufrufen (ALTER DATABASE <name> SET RECURSIVE_TRIGGERS ON;)

Page 9: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

AFTER Trigger

inserted und deleted Spezialtabelleninserted: Zeilen für INSERT und UPDATEdeleted: Zeilen für UPDATE und DELETE

Mehrere Trigger pro Objekt möglich (Reihenfolge nur als „first“ und „last“; sp_settriggerorder)

Page 10: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

INSTEAD OF Trigger

Original-Anweisung wird durch den Code des Triggers komplett ersetztinserted und deleted enthalten die Daten, die geändert worden *wären*!Nie rekursiv, immer nur einer pro OperationAuch auf Sichten möglichWerden *vor* contraint-Prüfung ausgeführt

Page 11: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

DDL Trigger

Auf Datenbank oder ServerebeneFür einzelne DDL Ereignisse oder GruppenEVENTDATA() FunktionNur AFTER Trigger

CREATE TRIGGER ddlTrigger ON DATABASE FOR DROP_TABLE

Page 12: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

CLR Trigger

Trigger können seit SQL Server 2005 in .NET geschrieben werden Zugriff auf die .NET KlassenbibliothekenZugriff auf externe Ressourcen

Warnung: Transaktion erst beendet, wenn Trigger fertig! Externe Aufrufe eine Sicherheitsproblem!

[SqlTrigger(Event=„FOR INSERT“)]public static void trg_LogToEventlog() { …

Page 13: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Agenda

Aktive KomponentenDML- und DDL-TriggerEvent NotificationsAusblick SQL Server 2008

Page 14: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Trigger bieten im Vergleich zu Event Notifications den Vorteil, dass sie im Kontext der sie auslösenden Transaktion ablaufen (und sie daher auch zurückrollen können). Gleichzeitig leiden sie aber auch an dem eklatanten Nachteil, dass sie im Kontext der sie auslösenden Transaktion ablaufen (und die Transaktion folglich warten muss, bis jegliche Triggeraktivität beendet ist, ehe sie fortfahren kann)!

WAITFOR DELAY ‚0:03‘; …

Page 15: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Event Notifications

„Asynchrone Antworten auf ein Ereignis“Können keine Transaktionen zurückrollen!

Trigger: Reaktion auf DML und DDL EreignisseFühren Code aus

Event Notifications: Reaktion auf DDL und Trace/Performance Ereignisse (CREATE TABLE, LOCK_DEADLOCK,…)Senden XML-Nachrichten

Page 16: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Voraussetzungen für Event Notifications

SQL Server 2005 oder neuerService Broker Nachrichtenwarteschlange muss aktiviert seinEin Dienst, der auf EN reagiert, muss erstellt werden Erweiterte Service Broker Funktionalität (Aktivierung, …) kann genutzt werden

Page 17: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Agenda

Aktive KomponentenDML- und DDL-TriggerEvent NotificationsAusblick SQL Server 2008

Page 18: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Management by Intent

TodayFrom Managing by scripts

By default SQL Server 2005 turns off sensitive features e.g. CLR, Database Mail and OLE Automation

To enable CLR and Database Mail the DBA must either:

Use Surface Area Configurator (SAC) tool to explicitly enable these features ORUse T-SQL script to do so

To monitor compliance the DBA will manually run SAC or her script regularly

TomorrowTo Management by Policies

In Katmai, Declarative Management Framework (DMF) will offer easy configuration, automation and enforcement

To enable CLR and Database Mail with DMF, the DBA will simply

Define a policy to enable these featuresFrom Management Studio simply run the policy

Compliance checking: DMF will automatically enforce the policy

based on a schedule ORit will check once a user changes the configuration

Reporting: DMF reports policy violation each time it occurs

Can run on multiple servers automatically

Page 19: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Advanced Performance Analysis

Extensible Data Collector

• Katmai will collect performance data e.g. memory usage, disk usage, etc

• User can also define other sets of events for tracking

Performance Data Warehouse

• The Performance data warehouse will store deep data on SQL Server’s performance including query performance and locking issues

• The data can be analyzed to offer deep insights on SQL Server’s performance

Rich Performance Reports

• Historical data on database performance will be displayed in rich reports

• Reports will allow drill downs for root cause analysis

Page 20: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Administratives…

PASS – Professional Association for SQL Server

„Die“ SQL Server Nutzergruppe!www.sqlpass.de Regelmäßige SQL Server Workshops und BootCampsNutzergruppentreffen – von Usern für UserSQL Jedis und SQL Rookies – jeder ist willkommen

Page 21: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Ressourcen SQL Server

http://www.microsoft.com/sqlhttp://connect.microsoft.com/SQLServer http://forums.microsoft.com/MSDN http://www.microsoft.com/vhd MSDN AA für Informatik-Studenten!Inside SQL Server Buch-ReiheData Mining with Microsoft SQL Server 2005 (Tang, MacLennan)Microsoft Certified Professional, Technology Specialist, IT Professional, …http://www.microsoft.com/mcp

Page 22: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Microsoft Student Program

Friedrich-Schiller-Universität JenaFakultät für Mathematik und Informatik

Page 23: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

25

Microsoft Software für Euch kostenlos!!!

• Betriebssysteme (Vista, XP, 2003, …)• SQL Server 2005• Visual Studio 2005• Office Visio, Project, Access, InfoPath• …

Euer Ansprechpartner:Dr. Günter Schorr (EAP Raum 3416)

MSDN - Academic Alliance

Page 24: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

26

Veranstaltungen an der FSU Jena

ASP.NET 2.0 Workshop• 24.-25. März 2007• 12.-13. Mai 2007

… weitere Veranstaltungen in Planung!Ankündigung unter: www.dotnetcommunity.de

Page 25: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

27

Microsoft Student Partner an der FSU Jena

Stefan Kontschinsky(Dipl. Informatik)

[email protected]

Auch Student Partner werden:www.studentprogram.de

Page 26: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Fragen

Page 27: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com
Page 28: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Was ist neu am SQL Server 2005.NET Framework

Common Language Runtime IntegrationUser-defined AggregatesUser-defined Data TypesUser-defined FunctionsSQL Server .NET Data ProviderExtended Triggers

Data TypesManaged SQL TypesNew XML Datatype

SQL Server EngineNew Message Service BrokerHTTP Support (Native HTTP)Database Tuning Advisor Multiple Active Result Sets Persisted Computed ColumnsQueuing SupportSnapshot Isolation Level Scale Up PartitioningVIA support NUMA support

Database Failure and RedundancyFail-over Clustering (up to 8 node)Enhanced Multi-instance SupportDatabase MirroringDatabase Viewpoints

XMLXQUERY Support (Server & Mid Tier)XML Data Manipulation Language FOR XML EnhancementsXML Schema (XSD) Support MSXML 6.0 (Native).Net XML Framework

Notification Services & SQL Server CE

Database MaintenanceBackup and Restore EnhancementsChecksum Integrity ChecksDedicated Administrator ConnectionDynamic AWEFast RecoveryHighly-available UpgradeOnline Index OperationsOnline RestoreParallel DBCCParallel Index Operations

Management ToolsNew Management StudioMDX Query EditorVersion Control SupportXML/ASQLCMD Command Line Tool

Performance Tuning Profiler EnhancementsProfiling Analysis ServicesExportable Showplan Exportable Deadlock Traces

Full-text SearchIndexing of XML Datatype

MDAC Side by Side installationMicrosoft Installer base setupSupport for Active Directory

DeploymentSQL Client .NET Data Provider

Server Cursor SupportAsynch

SecurityAll Permissions GrantableFine Grain Administration RightsSeparation of Users and Schema

ReplicationAuto-tuning Replication AgentsOracle PublicationImproved Blob Change Tracking

OLAP and Data MiningAnalysis Management Objects Windows Integrated Backup and RestoreWeb Service/XML for AnalysisDTS and DM IntegrationNew Data Mining AlgorithmsAuto Packaging and Deployment

Data Transformation ServicesNew Architecture (DTR + DTP)Complex Control FlowsControl Flow DebuggingFor Each EnumerationsProperty MappingsFull Data Flow DesignerFull DTS Control Flow DesignerGraphical Presentation of Pkg ExecutionImmediate Mode and Project ModePackage (Advanced) Deployment ToolsCustom Tasks and Transformations

Reporting ServicesMultiple Output Formats Parameters (Static, Dynamic,

Hierarchical)Bulk Delivery of Personalized ContentSupport Multiple Data Sources STS (Web Parts, Doc Libraries)Visual Design ToolCharting, Sorting, Filtering, Drill-ThroughScheduling, CachingComplete Scripting EngineScale Out architectureOpen XML Report Definition

Page 29: Trigger und Event Notifications im SQL Server 2005 Artus Krohn-Grimberghe Ehem. Student Partner Microsoft Student Program artuskg@gmail.com

Transparent Data EncryptionExternal Key ManagementData AuditingPluggable CPUTransparent Failover for Database MirroringDeclarative Management FrameworkServer Group ManagementStreamlined InstallationEnterprise System ManagementPerformance Data CollectionSystem AnalysisData CompressionQuery Optimization ModesResource GovernorEntity Data ModelLINQVisual Entity DesignerEntity Aware Adapters

SQL Server Change Tracking

Synchronized Programming Model

Visual Studio Support

SQL Server Conflict Detection

FILESTREAM data type

Integrated Full Text Search

Sparse Columns

Large User Defined Types

Date/Time Data Type

LOCATION data type

SPATIAL data type

Virtual Earth Integration

Partitioned Table Parallelism

Query Optimizations

Persistent Lookups

Change Data Capture

Backup Compression

MERGE SQL Statement

Data Profiling

Star Join

Enterprise Reporting Engine

Internet Report Deployment

Block Computations

Scale out Analysis

BI Platform Management

Export to Word and Excel

Author reports in Word and Excel

Report Builder Enhancements

TABLIX

Rich Formatted Data

Personalized Perspectives

… and many more