chamara
chamara

Reputation: 12711

RAISERROR Syntax error in SQL Server 2014

I'm working on migrating SQL Server 2008 R2 database to SQL Server 2014. Having trouble with the following trigger. Looks like something with RAISEERROR is not supported in newer version.

ALTER TRIGGER [dbo].[Route_ITrig] 
ON [dbo].[Route] 
FOR INSERT AS
    /*
     * PREVENT NULL VALUES IN 'RouteName'
     */
    IF (SELECT Count(*) FROM inserted WHERE RouteName IS NULL) > 0
    BEGIN
        RAISERROR 44444 'Field ''RouteName'' cannot contain a null value.'
        ROLLBACK TRANSACTION
    END

This is the error I'm getting

Msg 102, Level 15, State 1, Procedure Route_ITrig, Line 15
Incorrect syntax near '44444'

Upvotes: 0

Views: 2487

Answers (1)

Shubham Pandey
Shubham Pandey

Reputation: 1019

This is a SQL function, hence all required variables must be passed in brackets, as follows:

RAISERROR(44444, 'Field ', 'RouteName', ' cannot contain a null value.')

Upvotes: 1

Related Questions