关键字' TRIGGER'附近的语法不正确

时间:2018-01-07 20:02:07

标签: sql-server tsql database-trigger

public privileged aspect TimeManagement {
pointcut constConnection() : 
    execution(telecom.v2.connect.Connection.new(..));

pointcut completepc() : execution(* 
   telecom.v2.connect.Connection.complete()) ;

Timer Connection.timer; // here i define my variable in connection

after():constConnection(){
    timer = new Timer();
}

after():completepc(){       
    timer.start(); // here i use it but the error is appeared 
}

我收到此错误:

  

Msg 156,Level 15,State 1,Procedure SegmentasyonSagla,107行[Batch Start line 3]
  关键字' TRIGGER'附近的语法不正确。

你能帮我解决这个错误谢谢:)

1 个答案:

答案 0 :(得分:0)

我想,您正尝试在名为SegmentasyonSagla的过程中创建触发器。您应该使用动态查询来创建触发器。

CREATE PROC AirportCodeDegisProc
as
begin
    declare @query nvarchar(max) = '
    CREATE TRIGGER AirportCodeDegis
        ON ActiveEvaluations
        INSTEAD OF UPDATE
    AS
    BEGIN
        SET NOCOUNT ON;
        DECLARE @Silinen_AirportCode nvarchar(10) = (SELECT deleted.Airport_code FROM deleted);
        DECLARE @Yeni_AirportCode nvarchar(10) = (SELECT inserted.Airport_code FROM inserted);

        -- Airport Tablosunda güncellenen Airport_code değerini, CAN_LAND tablosunun içindeki airport_code değerine atamaktadır..
        IF (SELECT COUNT(*) FROM CAN_LAND WHERE CAN_LAND.Airport_code = @Silinen_AirportCode) != 0
            BEGIN 
                UPDATE CAN_LAND SET Airport_code = @Yeni_AirportCode WHERE Airport_code = @Silinen_AirportCode; 
            END

        -- Airport Tablosunda güncellenen airport_code değerini, FLIGHT_LEG tablosunun içindeki Arrival_airport_code değerine atamaktadır..
        IF (SELECT COUNT(*) FROM FLIGHT_LEG WHERE FLIGHT_LEG.Arrival_airport_code = @Silinen_AirportCode) != 0
            BEGIN 
                UPDATE FLIGHT_LEG SET Arrival_airport_code = @Yeni_AirportCode WHERE Arrival_airport_code = @Silinen_AirportCode; 
            END

        -- Airport Tablosunda güncellenen airport_code değerini, FLIGHT_LEG tablosunun içindeki Departure_airport_code değerine atamaktadır..
        IF (SELECT COUNT(*) FROM FLIGHT_LEG WHERE Departure_airport_code = @Silinen_AirportCode) != 0
            BEGIN
                UPDATE FLIGHT_LEG SET Departure_airport_code = @Yeni_AirportCode WHERE Departure_airport_code = @Silinen_AirportCode; 
            END

        -- Airport Tablosunda güncellenen airport_code değerini, LEG_INSTANCE tablosunun içindeki Arrival_airport_code değerine atamaktadır..
        IF (SELECT COUNT(*) FROM LEG_INSTANCE WHERE LEG_INSTANCE.Arrival_airport_code = @Silinen_AirportCode) != 0
            BEGIN 
                UPDATE LEG_INSTANCE SET Arrival_airport_code = @Yeni_AirportCode WHERE Arrival_airport_code = @Silinen_AirportCode; 
            END

        -- Airport Tablosunda güncellenen airport_code değerini, LEG_INSTANCE tablosunun içindeki Departure_airport_code değerine atamaktadır..
        IF (SELECT COUNT(*) FROM LEG_INSTANCE WHERE LEG_INSTANCE.Departure_airport_code = @Silinen_AirportCode) != 0
            BEGIN 
                UPDATE LEG_INSTANCE SET Departure_airport_code = @Yeni_AirportCode WHERE Departure_airport_code = @Silinen_AirportCode; 
            END

        SET NOCOUNT OFF;
    END;'
    EXECUTE sp_executesql @query
end