Database Reference
In-Depth Information
This query produces the expected result:
We can even use the function multiple times in the same SQL statement, as shown in
SQL-Query-CH07-04, which is a variant on the SQL query we used to create the SQL view
CustomerInterestView in our discussion of SQL views:
/* *** SQL-Query-CH07-04 *** */
SELECT dbo.NameConcatenation(C.FirstName, C.LastName) AS CustomerName,
dbo.NameConcatenation(A.FirstName, A.LastName) AS ArtistName
FROM CUSTOMER AS C JOIN CUSTOMER_ARTIST_INT AS CAI
ON C.CustomerID = CAI.CustomerID
JOIN ARTIST AS A
ON CAI.ArtistID = A.ArtistID
ORDER BY CustomerName, ArtistName;
This query produces the expected large result that is shown in Figure 7-22, where we see
that both CustomerName and ArtistName display the names in the LastName, FirstName
syntax produced by the NameConcatenation user-defined function. Compare the results in
this figure to those in Figure 7-18, which presents essentially the same results, but without the
formatting provided by the NameConcatenation function.
Using SQL Triggers
A trigger is a stored program that is executed by the DBMS whenever a specified event
occurs. Triggers for Oracle Database are written in Java or in Oracle's PL/SQL. SQL Server
triggers are written in Microsoft .NET Common Language Runtime (CLR) languages, such
as Visual Basic .NET, or Microsoft's T-SQL. MySQL triggers are written in MySQL's variant of
SQL. In this chapter, we will discuss triggers in a generic manner without considering the par-
ticulars of those languages. We will discuss triggers written in DBMS-specific SQL variants in
Chapters 10A (T-SQL), 10B (PL/SQL), and 10C (MySQL SQL).
A trigger is attached to a table or a view. A table or a view may have many triggers,
but a trigger is associated with just one table or view. A trigger is invoked by an SQL DML
INSERT, UPDATE, or DELETE request on the table or view to which it is attached. Figure 7-23
summarizes the triggers available for SQL Server 2012, Oracle Database 11 g Release 2, and
MySQL 5.6.
Oracle Database 11 g Release 2 supports three kinds of triggers: BEFORE, INSTEAD OF,
and AFTER. As you would expect, BEFORE triggers are executed before the DBMS processes
the insert, update, or delete request. INSTEAD OF triggers are executed in place of any DBMS
processing of the insert, update, or delete request. AFTER triggers are executed after the insert,
 
 
Search WWH ::




Custom Search