Teachnique
      CourseRoadmaps
      Login

      HomeIntroductionFeaturesVersionsVariablesInstallationAdministrationPHP SyntaxNode.js SyntaxJava SyntaxPython SyntaxConnectionWorkbench

      Create DatabaseDrop DatabaseSelect DatabaseShow DatabaseCopy DatabaseDatabase ExportDatabase ImportDatabase Info

      Create UsersDrop UsersShow UsersChange PasswordGrant PrivilegesShow PrivilegesRevoke PrivilegesLock User AccountUnlock User Account

      Create TablesShow TablesAlter TablesRename TablesClone TablesTruncate TablesTemporary TablesRepair TablesDescribe TablesAdd/Delete ColumnsShow ColumnsRename ColumnsTable LockingDrop TablesDerived Tables

      QueriesConstraintsInsert QuerySelect QueryUpdate QueryDelete QueryReplace QueryInsert IgnoreInsert on Duplicate Key UpdateInsert Into Select

      Create ViewsUpdate ViewsDrop ViewsRename Views

      IndexesCreate IndexDrop IndexShow IndexesUnique IndexClustered IndexNon-Clustered Index

      Where ClauseLimit ClauseDistinct ClauseOrder By ClauseGroup By ClauseHaving ClauseAND OperatorOR OperatorLike OperatorIN OperatorANY OperatorEXISTS OperatorNOT OperatorNOT EQUAL OperatorIS NULL OperatorIS NOT NULL OperatorBetween OperatorUNION OperatorUNION vs UNION ALLMINUS OperatorINTERSECT OperatorINTERVAL Operator

      Using JoinsInner JoinLeft JoinRight JoinCross JoinFull JoinSelf JoinDelete JoinUpdate JoinUnion vs Join

      Unique KeyPrimary KeyForeign KeyComposite KeyAlternate Key

      TriggersCreate TriggerShow TriggerDrop TriggerBefore Insert TriggerAfter Insert TriggerBefore Update TriggerAfter Update TriggerBefore Delete TriggerAfter Delete Trigger

      Data TypesVARCHARBOOLEANENUMDECIMALINTFLOATBITTINYINTBLOBSET

      Regular ExpressionsRLIKE OperatorNOT LIKE OperatorNOT REGEXP Operatorregexp_instr() Functionregexp_like() Functionregexp_replace() Functionregexp_substr() Function

      Fulltext SearchNatural Language Fulltext SearchBoolean Fulltext SearchQuery Expansion Fulltext Searchngram Fulltext Parser

      Date and Time FunctionsArithmetic OperatorsNumeric FunctionsString FunctionsAggregate Functions

      NULL ValuesTransactionsUsing SequencesHandling DuplicatesSQL InjectionSubQueryCommentsCheck ConstraintsStorage EnginesExport Table into CSV FileImport CSV File into DatabaseUUIDCommon Table ExpressionsOn Delete CascadeUpsertHorizontal PartitioningVertical PartitioningCursorStored FunctionsSignalResignalCharacter SetCollationWildcardsAliasROLLUPToday DateLiteralsStored ProcedureExplainJSONStandard DeviationFind Duplicate RecordsDelete Duplicate RecordsSelect Random RecordsShow ProcesslistChange Column TypeReset Auto-IncrementCoalesce() Function

      Useful FunctionsStatements ReferenceQuick GuideUseful ResourcesDiscussion

      Feedback

      Submit request if you have any questions.

      Course
      Drop Trigger

      MySQL Tutorial

      This SQL tutorial is structured for beginners to guide them from the foundational concepts to advanced data manipulation and querying techniques in SQL. By the end of this tutorial, you will have developed a robust understanding of SQL, equipping you with the knowledge to efficiently manage and analyze data across various database systems. This guide sets the stage for your growth into a skilled data professional, ready to tackle complex data challenges and contribute to the field of data analysis and database management.

      DROP TRIGGER

      Triggers in MySQL are stored programs similar to procedures. These can be created on a table, schema, view and database that are associated with an event and whenever an event occurs the respective trigger is invoked.
      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).
      You can delete a trigger using the DROP TRIGGER Statement.

      Dropping Trigger in MySQL

      The DROP TRIGGER statement in MySQL will drop a trigger from a database, and all its information.

      Syntax

      Following is the syntax of the MySQL DELETE TRIGGER Statement.
      DROP TRIGGER [IF EXISTS] trigger_name
      
      Where, trigger_name is the name of the trigger you need to delete.

      Example

      Assume we have created a table with name student as shown below −
      CREATE TABLE STUDENT(
      Name varchar(35),
      Age INT,
      Score INT
      );
      
      Following query creates a trigger named sample_trigger on this table. This trigger will set the score value 0 if you enter a value that is less than 0 as score.
      DELIMITER //
      CREATE TRIGGER sample_trigger
      BEFORE INSERT ON STUDENT
      FOR EACH ROW
      BEGIN
      IF NEW.score < 0 THEN SET NEW.score = 0;
      END IF;
      END //
      DELIMITER ;
      
      Now, let us use the following query to drop the trigger we created in the previous step −
      DROP TRIGGER sample_trigger;
      

      Verification

      To verify if the trigger has been dropped, let us display the trigger information using the following query −
      SHOW TRIGGERS\G
      
      Since have deleted the trigger created, we get an empty set −
      Empty set (0.11 sec)
      

      With IF EXISTS clause

      If you try to drop a trigger that doesn't exist an error will be generated as shown below −
      DROP TRIGGER demo;
      
      Following is the output −
      ERROR 1360 (HY000): Trigger does not exist
      
      If you use the IF EXISTS clause along with the DROP TRIGEGR statement as shown below, the specified trigger will be dropped and if a trigger with the given name, doesn't exist the query will be ignored.
      DROP TRIGGER IF EXISTS demo;
      

      Dropping Trigger Using a Client Program

      In addition to create or show a trigger, we can also drop a trigger using a client program.

      Syntax

      PHPNodeJSJavaPython
      To drop a trigger through a PHP program, we need to execute the DROP TRIGGER statement using the mysqli function query() as follows −
      $sql = "Drop TRIGGER testTrigger";
      $mysqli->query($sql);
      

      Example

      Following are the programs −
      PHPNodeJSJavaPython
      $dbhost = 'localhost';
      $dbuser = 'root';
      $dbpass = 'password';
      $db = 'TUTORIALS';
      $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $db);
      if($mysqli->connect_errno ) {
      printf("Connect failed: %s", $mysqli->connect_error);
      exit();
      }
      //printf('Connected successfully.');
      $sql = "DROP TRIGGER testTrigger";
      if($mysqli->query($sql)){
      printf("Trigger dropped successfully...!");
      }
      if($mysqli->error){
      printf("Failed..!" , $mysqli->error);
      }
      $mysqli->close();
      

      Output

      The output obtained is as follows −
      Trigger dropped successfully...!