How do we configure our TFS gated build validation to catch parser validation errors?
For example, we had a stored procedure with an invalid statement that kept passing the gated TFS check-in XAML build validation and even passed SSDT publish to a SQL Server 2008R2 database for two whole years!
CREATE PROCEDURE This_Should_Fail
AS BEGIN
DECLARE @TableVariable TABLE(
ID INT IDENTITY(1, 1),
Name VARCHAR(MAX)
)
SELECT DISTINCT TOP 1 Name
FROM @TableVariable
ORDER BY ID
END
When I run this statement I get the appropriate error, however when I run the full version in TFS there is no error!
Msg 145, Level 15, State 1, Procedure This_Should_Fail, Line 7 ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
But the error was never encountered until recently when the definition changed to be like this, which doesn't even throw any errors when run!
CREATE PROCEDURE This_Should_Fail
AS BEGIN
DECLARE @TableVariable TABLE(
ID INT IDENTITY(1, 1),
Name VARCHAR(MAX),
ForeignKeyID INT
)
--create some sample data
INSERT INTO @TableVariable(Name, ForeignKeyID)
VALUES ('Obj1', 999), ('Obj2', 999), ('Obj3', 0), ('Obj4', 0)
DECLARE @ForeignKeyID INT = 999--some lookup here
SELECT DISTINCT TOP 1 Name
FROM @TableVariable
WHERE ForeignKeyID = @ForeignKeyID
END
And it took a whole month after that change was made before the change in the TFS branch failed to deploy anywhere. In both cases, there was no ordering by all selected columns.
This is confusing me even more because neither version in TFS (which I can't include because it's my company's IP) throws any error even when manually run in SSMS 2014!
Thanks.