Difference between revisions of "CREATE TRIGGER"

From Lianjapedia
Jump to: navigation, search
(Products)
 
(Description)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Creates a trigger for a table
 
Creates a trigger for a table
 
  
 
==Syntax==
 
==Syntax==
 
CREATE TRIGGER ON [<database>!]&#060;table&#062;
 
CREATE TRIGGER ON [<database>!]&#060;table&#062;
  
FOR UPDATE | INSERT | DELETE
+
FOR DELETE | ONAFTERDELETE | INSERT | ONAFTERINSERT | UPDATE | ONAFTERUPDATE
  
 
AS <expression>
 
AS <expression>
 
  
 
==See Also==
 
==See Also==
[[ADD TABLE]], [[ALTER INDEX]], [[ALTER TABLE]], [[SQL Constraints|CONSTRAINTS]], [[SQL Data Types|DATA TYPES]], [[DB_DATADIR]], [[DELETE TRIGGER]], [[DROP TABLE]], [[GETENV()]], [[SQL INSERT|INSERT]], [[SQL SELECT|SELECT]], [[SET AUTOCATALOG]], [[SET TCACHE]], [[SET XMLFORMAT]],  
+
[[ADD TABLE]], [[ALTER INDEX]], [[ALTER TABLE]], [[SQL Constraints|CONSTRAINTS]], [[SQL Data Types|DATA TYPES]], [[DELETE TRIGGER]], [[DROP TABLE]], [[GETENV()]], [[SQL INSERT|INSERT]], [[SQL SELECT|SELECT]], [[SET AUTOCATALOG]], [[SET XMLFORMAT]],  
 
+
  
 
==Description==
 
==Description==
 
The CREATE TRIGGER command is used to create a trigger for the specified table.  Triggers cause the logical <expression> to be evaluated when certain operations are attempted.
 
The CREATE TRIGGER command is used to create a trigger for the specified table.  Triggers cause the logical <expression> to be evaluated when certain operations are attempted.
  
 
+
{| class="wikitable" width="100%"
 
+
!width="50%"|Trigger||Operation
{| class="wikitable"
+
!Trigger||Operation
+
 
|-
 
|-
|UPDATE||Attempt to modify an existing record
+
|valign="top"|DELETE||Attempt to delete an existing record.  Corresponds to onbeforedelete trigger in listings.
 
|-
 
|-
|INSERT||Attempt to add a new record
+
|valign="top"|ONAFTERDELETE||After deleting an existing record
 
|-
 
|-
|DELETE||Attempt to delete an existing record
+
|valign="top"|INSERT||Attempt to add a new record.  Corresponds to onbeforeinsert trigger in listings.
 +
|-
 +
|valign="top"|ONAFTERINSERT||After adding a new record
 +
|-
 +
|valign="top"|UPDATE||Attempt to modify an existing record.  Corresponds to onbeforeupdate trigger in listings.
 +
|-
 +
|valign="top"|ONAFTERUPDATE||After modifying an existing record
 
|-
 
|-
 
|}
 
|}
 
  
 
If the <expression> evaluates to False (.F.) the operation does not complete.  If the <expression> evaluates to True (.T.) the operations does complete.
 
If the <expression> evaluates to False (.F.) the operation does not complete.  If the <expression> evaluates to True (.T.) the operations does complete.
  
 
+
{| class="wikitable" width="100%"
{| class="wikitable"
+
!width="50%"|Keywords||Description
!Keywords||Description
+
 
|-
 
|-
|database||The name of the database to which the table belongs.  Databases in Recital are implemented as directories containing files that correspond to the tables and associated files in the database.  Operating System file protection can be applied individually to the files for added security.  The directory is a sub-directory of the Recital data directory.  The environment variable / symbol DB_DATADIR points to the current Recital data directory and can be queried using the GETENV() function.  Files from other directories can be added to the database using the ADD TABLE command or via the database catalog and SET AUTOCATALOG functionality.  The '!' character must be included between the database name and the table name.
+
|valign="top"|database||The name of the database to which the table belongs.
 
|-
 
|-
 
|table||The name of the table
 
|table||The name of the table
 
|-
 
|-
|FOR UPDATE | INSERT | DELETE||Specifies the type of trigger to be created.
+
|FOR DELETE &#124; ONAFTERDELETE &#124; INSERT &#124; ONAFTERINSERT &#124; UPDATE &#124; ONAFTERUPDATE||valign="top"|Specifies the type of trigger to be created.
 
|-
 
|-
 
|expression||A logical expression to be evaluated
 
|expression||A logical expression to be evaluated
 
|-
 
|-
 
|}
 
|}
 
  
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
USE accounts
+
CREATE TRIGGER ON customers FOR UPDATE AS not empty(custid)
CREATE TRIGGER ON customer FOR UPDATE AS not empty(CustName)
+
 
</code>
 
</code>
 
+
 
+
==Products==
+
Recital Server, Recital
+
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:SQL]]
 
[[Category:SQL]]
 
[[Category:Commands]]
 
[[Category:Commands]]
[[Category:Triggers]]
+
[[Category:Databases]]
 +
[[Category:Lianja VFP Extensions]]
 +
[[Category:VFP Command Extensions]]
 +
[[Category:Database Triggers]]

Latest revision as of 09:36, 22 December 2017

Purpose

Creates a trigger for a table

Syntax

CREATE TRIGGER ON [<database>!]<table>

FOR DELETE | ONAFTERDELETE | INSERT | ONAFTERINSERT | UPDATE | ONAFTERUPDATE

AS <expression>

See Also

ADD TABLE, ALTER INDEX, ALTER TABLE, CONSTRAINTS, DATA TYPES, DELETE TRIGGER, DROP TABLE, GETENV(), INSERT, SELECT, SET AUTOCATALOG, SET XMLFORMAT,

Description

The CREATE TRIGGER command is used to create a trigger for the specified table. Triggers cause the logical <expression> to be evaluated when certain operations are attempted.

Trigger Operation
DELETE Attempt to delete an existing record. Corresponds to onbeforedelete trigger in listings.
ONAFTERDELETE After deleting an existing record
INSERT Attempt to add a new record. Corresponds to onbeforeinsert trigger in listings.
ONAFTERINSERT After adding a new record
UPDATE Attempt to modify an existing record. Corresponds to onbeforeupdate trigger in listings.
ONAFTERUPDATE After modifying an existing record

If the <expression> evaluates to False (.F.) the operation does not complete. If the <expression> evaluates to True (.T.) the operations does complete.

Keywords Description
database The name of the database to which the table belongs.
table The name of the table
FOR DELETE | ONAFTERDELETE | INSERT | ONAFTERINSERT | UPDATE | ONAFTERUPDATE Specifies the type of trigger to be created.
expression A logical expression to be evaluated

Example

CREATE TRIGGER ON customers FOR UPDATE AS not empty(custid)