Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL Server Management Studio 2014, the New Trigger menu option is disabled

enter image description here

I want to add a new trigger to my table. As seen in the picture, New Trigger button is not active. new index, new column, new contraints, new statics is active.

I do not understand what is the problem.

like image 421
pak Avatar asked Nov 11 '14 17:11

pak


People also ask

How do I enable triggers in SQL Server?

Enabling and disabling DML triggers on a table. Navigate to triggers folder at the table level, select the trigger, Right click on trigger and Click on Enable/Disable to Enable or disable the trigger using SSMS. Disabling specific SQL Server trigger on a table using T-SQL.

Can triggers be enabled or disabled?

Triggers can be re-enabled by using ENABLE TRIGGER. DML triggers defined on tables can be also be disabled or enabled by using ALTER TABLE. Changing the trigger by using the ALTER TRIGGER statement enables the trigger.

What are 3 types of SQL triggers?

SQL Server has three types of triggers: DML (Data Manipulation Language) Triggers. DDL (Data Definition Language) Triggers. Logon Triggers.

How do I find triggers in SQL Server Management Studio?

Using SQL Server Management Studio Expand the database that you want, expand Tables, and then expand the table that contains the trigger for which you want to view the definition. Expand Triggers, right-click the trigger you want, and then click Modify. The definition of the DML trigger appears in the query window.


2 Answers

You don't need to use the menu item to create a trigger. Just open up a query window and write the create trigger statement there.

To get some help with the syntax you can use a snippet in the editor. Right click on the surface of the query editor and select Insert Snippet and then select Trigger and Create Trigger to get the following code snippet inserted to your editor.

CREATE TRIGGER TriggerName
    ON [dbo].[TableName]
    FOR DELETE, INSERT, UPDATE
    AS
    BEGIN
    SET NOCOUNT ON
    END

The menu item (if you get it to work) will do almost the same thing only it will use a template that looks like this:

-- ================================================
-- Template generated from Template Explorer using:
-- Create Trigger (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- See additional Create Trigger templates for more
-- examples of different Trigger statements.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE TRIGGER <Schema_Name, sysname, Schema_Name>.<Trigger_Name, sysname, Trigger_Name> 
   ON  <Schema_Name, sysname, Schema_Name>.<Table_Name, sysname, Table_Name> 
   AFTER <Data_Modification_Statements, , INSERT,DELETE,UPDATE>
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for trigger here

END
GO
like image 75
Mikael Eriksson Avatar answered Sep 22 '22 12:09

Mikael Eriksson


A similar question was asked here: SQL Server Express 'NEW TRIGGER' BUTTON IS DISABLED

I hope this can help you!

like image 28
Zachary Vorwaller Avatar answered Sep 22 '22 12:09

Zachary Vorwaller