SQL commands
SQL commands
TRUNCATE TABLE t;
Remove all data in a table
MANAGING VIEWS MANAGING INDEXES MANAGING TRIGGERS
CREATE VIEW v(c1,c2) CREATE INDEX idx_name CREATE OR MODIFY TRIGGER trigger_name
AS ON t(c1,c2); WHEN EVENT
SELECT c1, c2 Create an index on c1 and c2 of the table t ON table_name TRIGGER_TYPE
FROM t; EXECUTE stored procedure;
Create a new view that consists of c1 and c2 CREATE UNIQUE INDEX idx_name Create or modify a trigger
ON t(c3,c4);
CREATE VIEW v(c1,c2) Create a unique index on c3, c4 of the table t WHEN
AS •BEFORE –invoke before the event occurs
SELECT c1, c2 DROP INDEX idx_name; •AFTER –invoke after the event occurs
FROM t; Drop an index
EVENT
WITH [CASCADED | LOCAL] CHECK OPTION;
•INSERT –invoke for INSERT
Create a new view with check option
•UPDATE –invoke for UPDATE
SQL AGGREGATE FUNCTIONS •DELETE –invoke for DELETE
CREATE RECURSIVEVIEW v
AS
TRIGGER_TYPE
select-statement--anchor part AVG returns the average of a list
•FOR EACH ROW
UNION [ALL] •FOR EACH STATEMENT
select-statement;--recursive part COUNT returns the number of elements of a list
Create a recursive view
SUM returns the total of a list
CREATE TRIGGER before_insert_person
CREATE TEMPORARYVIEW v
BEFORE INSERT
AS MAX returns the maximum value in a list
ON person FOR EACH ROW
SELECT c1, c2
EXECUTE stored procedure;
FROM t; MIN returns the minimum value in a list
Create a trigger invoked before a new row is
Create a temporary view
inserted into the person table
DROP VIEW view_name
DROP TRIGGER trigger_name
Delete a view
Delete a specific trigger