background preloader

Programming SQL and MySQL

Facebook Twitter

Find duplicate values in SQL Server. PL/SQL Triggers. Triggers are stored programs, which are automatically executed or fired when some events occur. Triggers are, in fact, written to be executed in response to any of the following events: A database manipulation (DML) statement (DELETE, INSERT, or UPDATE).A database definition (DDL) statement (CREATE, ALTER, or DROP).A database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, or SHUTDOWN). Triggers could be defined on the table, view, schema, or database with which the event is associated. Benefits of Triggers Triggers can be written for the following purposes: Generating some derived column values automaticallyEnforcing referential integrityEvent logging and storing information on table accessAuditing Synchronous replication of tablesImposing security authorizationsPreventing invalid transactions Creating Triggers The syntax for creating a trigger is: Where, Example: To start with, we will be using the CUSTOMERS table we had created and used in the previous chapters: Trigger created.

PostgreSQL - php - Undefined function pg_connect() SQL - CHECK Constraint. The CHECK Constraint enables a condition to check the value being entered into a record. If the condition evaluates to false, the record violates the constraint and isn't entered into the table. Example: For example, the following SQL creates a new table called CUSTOMERS and adds five columns.

Here, we add a CHECK with AGE column, so that you can not have any CUSTOMER below 18 years: If CUSTOMERS table has already been created, then to add a CHECK constraint to AGE column, you would write a statement similar to the following: You can also use following syntax, which supports naming the constraint in multiple columns as well: ALTER TABLE CUSTOMERS ADD CONSTRAINT myCheckConstraint CHECK(AGE >= 18); DROP a CHECK Constraint: To drop a CHECK constraint, use the following SQL. ALTER TABLE CUSTOMERS DROP CONSTRAINT myCheckConstraint; SQL Tutorial. MySQL Tutorial.