SQL Server Business Intelligence

Download Report

Transcript SQL Server Business Intelligence

Trigger und Event Notifications im
SQL Server 2005
Artus Krohn-Grimberghe
Ehem. Student Partner
Microsoft Student Program
[email protected]
Microsoft SQL Server 2005 Architektur
Komponenten des
SQL Server 2005
Development Tools
Reporting Services
Analysis Services
OLAP & Data Mining
Integration Services
ETL
SQL Server
Relational Engine
Management Tools
RDBMS
ETL Werkzeug
OLAP Server
Data Mining
Reporting-Dienste
Management-Tools
Entwicklungs-Tools
Agenda
Aktive Komponenten
DML- und DDL-Trigger
Event Notifications
Ausblick SQL Server 2008
Aktive Komponenten
SQL Server Agent
Jobs (Automatisierung)
Alerts (Ereignis und Aktion)
Trigger
Event Notifications
Declarative Management Framework (ab
„Katmai“)
Agenda
Aktive Komponenten
DML- und DDL-Trigger
Event Notifications
Ausblick SQL Server 2008
DML- und DDL-Trigger
Prozeduren, die bei Datenbankereignissen
automatisch ausgeführt werden
Laufen 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-Trigger
AFTER- und INSTEAD OF-Trigger
T-SQL- und .NET-Trigger
Ausführung im Kontext
Zurückrollen der Transaktion möglich
Beim Zurückrollen entstehen doppelte
Kosten, daher n.M. constraints (Datentyp,
CHECK, DEFAULT, PK, FK, DRI) benutzen
Berechtigungskontext beachten!
CREATE TRIGGER trg1 ON dbo.tbl1 AFTER
INSERT
AS
IF EXISTS(SELECT * FROM inserted WHERE
col1 = <some_value>) ROLLBACK
TRANSACTION
Verschachtelung und Rekursion
Trigger können standardmäßig andere
Trigger auslösen
Trigger können sich selbst aufrufen (ALTER
DATABASE <name> SET
RECURSIVE_TRIGGERS ON;)
AFTER Trigger
inserted und deleted Spezialtabellen
inserted: Zeilen für INSERT und UPDATE
deleted: Zeilen für UPDATE und DELETE
Mehrere Trigger pro Objekt möglich
(Reihenfolge nur als „first“ und „last“;
sp_settriggerorder)
INSTEAD OF Trigger
Original-Anweisung wird durch den Code
des Triggers komplett ersetzt
inserted und deleted enthalten die Daten,
die geändert worden *wären*!
Nie rekursiv, immer nur einer pro Operation
Auch auf Sichten möglich
Werden *vor* contraint-Prüfung ausgeführt
DDL Trigger
Auf Datenbank oder Serverebene
Für einzelne DDL Ereignisse oder Gruppen
EVENTDATA() Funktion
Nur AFTER Trigger
CREATE TRIGGER ddlTrigger ON
DATABASE FOR DROP_TABLE
CLR Trigger
Trigger können seit SQL Server 2005 in .NET
geschrieben werden
Zugriff auf die .NET Klassenbibliotheken
Zugriff auf externe Ressourcen
Warnung: Transaktion erst beendet, wenn
Trigger fertig! Externe Aufrufe eine
Sicherheitsproblem!
[SqlTrigger(Event=„FOR INSERT“)]
public static void trg_LogToEventlog() { …
Agenda
Aktive Komponenten
DML- und DDL-Trigger
Event Notifications
Ausblick SQL Server 2008
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‘; …
Event Notifications
„Asynchrone Antworten auf ein Ereignis“
Können keine Transaktionen zurückrollen!
Trigger:
Reaktion auf DML und DDL Ereignisse
Führen Code aus
Event Notifications:
Reaktion auf DDL und Trace/Performance
Ereignisse (CREATE TABLE,
LOCK_DEADLOCK,…)
Senden XML-Nachrichten
Voraussetzungen für Event Notifications
SQL Server 2005 oder neuer
Service Broker Nachrichtenwarteschlange
muss aktiviert sein
Ein Dienst, der auf EN reagiert, muss erstellt
werden
Erweiterte Service Broker Funktionalität
(Aktivierung, …) kann genutzt werden
Agenda
Aktive Komponenten
DML- und DDL-Trigger
Event Notifications
Ausblick SQL Server 2008
Management by Intent
Today
Tomorrow
From Managing by scripts
To Management by Policies
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 OR
Use T-SQL script to do so
To monitor compliance the
DBA will manually run SAC or her
script regularly
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
features
From Management Studio simply run
the policy
Compliance checking: DMF will
automatically enforce the policy
based on a schedule OR
it will check once a user changes the
configuration
Reporting: DMF reports policy violation
each time it occurs
Can run on multiple servers
automatically
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
Administratives…
PASS – Professional Association for SQL
Server
„Die“ SQL Server Nutzergruppe!
www.sqlpass.de
Regelmäßige SQL Server Workshops und
BootCamps
Nutzergruppentreffen – von Usern für User
SQL Jedis und SQL Rookies – jeder ist
willkommen
Ressourcen SQL Server
http://www.microsoft.com/sql
http://connect.microsoft.com/SQLServer
http://forums.microsoft.com/MSDN
http://www.microsoft.com/vhd
MSDN AA für Informatik-Studenten!
Inside SQL Server Buch-Reihe
Data Mining with Microsoft SQL Server 2005
(Tang, MacLennan)
Microsoft Certified Professional,
Technology Specialist, IT Professional, …
http://www.microsoft.com/mcp
Microsoft Student Program
Friedrich-Schiller-Universität Jena
Fakultät für Mathematik und Informatik
MSDN - Academic Alliance
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)
25
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
26
Microsoft Student Partner an der FSU Jena
Stefan Kontschinsky
(Dipl. Informatik)
[email protected]
Auch Student Partner werden:
www.studentprogram.de
27
Fragen
Was ist neu am SQL Server 2005
.NET Framework
Database Maintenance
Replication
 Common Language Runtime Integration  Backup and Restore Enhancements
 Auto-tuning Replication Agents
 User-defined Aggregates
 Checksum Integrity Checks
 Oracle Publication
 User-defined Data Types
 Dedicated Administrator Connection
 Improved Blob Change Tracking
 User-defined Functions
 Dynamic AWE
OLAP and Data Mining
 SQL Server .NET Data Provider
 Fast Recovery
 Analysis Management Objects
 Extended Triggers
 Highly-available Upgrade
 Windows Integrated Backup and Restore
Data Types
 Online Index Operations
 Web Service/XML for Analysis
 Managed SQL Types
 Online Restore
 DTS and DM Integration
 New XML Datatype
 Parallel DBCC
 New Data Mining Algorithms
SQL Server Engine
 Parallel Index Operations
 Auto Packaging and Deployment
 New Message Service Broker
Management Tools
Data Transformation Services
 HTTP Support (Native HTTP)
 New Management Studio
 New Architecture (DTR + DTP)
 Database Tuning Advisor
 MDX Query Editor
 Complex Control Flows
 Multiple Active Result Sets
 Version Control Support
 Control Flow Debugging
 Persisted Computed Columns
 XML/A
 For Each Enumerations
 Queuing Support
 SQLCMD Command Line Tool
 Property Mappings
 Snapshot Isolation Level
Performance Tuning
 Full Data Flow Designer
 Scale Up Partitioning
 Profiler Enhancements
 Full DTS Control Flow Designer
 VIA support
 Profiling Analysis Services
 Graphical Presentation of Pkg Execution
 NUMA support
 Exportable Showplan
 Immediate Mode and Project Mode
Database Failure and Redundancy
 Exportable Deadlock Traces
 Package (Advanced) Deployment Tools
 Fail-over Clustering (up to 8 node)
Full-text Search
 Custom Tasks and Transformations
 Enhanced Multi-instance Support
 Indexing of XML Datatype
Reporting Services
 Database Mirroring
MDAC
 Multiple Output Formats
 Database Viewpoints
 Side by Side installation
 Parameters (Static, Dynamic, Hierarchical)
XML
 Microsoft Installer base setup
 Bulk Delivery of Personalized Content
 XQUERY Support (Server & Mid Tier)
 Support for Active Directory Deployment
 Support Multiple Data Sources
 XML Data Manipulation Language
SQL Client .NET Data Provider
 STS (Web Parts, Doc Libraries)
 FOR XML Enhancements
 Server Cursor Support
 Visual Design Tool
 XML Schema (XSD) Support
 Asynch
 Charting, Sorting, Filtering, Drill-Through
 MSXML 6.0 (Native)
Security
 Scheduling, Caching
 .Net XML Framework
 All Permissions Grantable
 Complete Scripting Engine
Notification Services & SQL Server CE
 Fine Grain Administration Rights
 Scale Out architecture
Transparent Data
Encryption
External Key Management
Data Auditing
Pluggable CPU
Transparent Failover for
Database Mirroring
Declarative Management
Framework
Server Group Management
Streamlined Installation
Enterprise System
Management
Performance Data
Collection
System Analysis
Data Compression
Query Optimization Modes
Resource Governor
Entity Data Model
LINQ
Visual Entity Designer
Entity 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
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
SPATIAL data type
Report Builder
Enhancements
Virtual Earth Integration
TABLIX
Partitioned Table Parallelism
Rich Formatted Data
Query Optimizations
Personalized
Perspectives
Persistent Lookups
… and many more
Change Data Capture
Backup Compression
MERGE SQL Statement
Data Profiling
Star Join