Today I faced the worst situation. There is a stored procedure in database, I had to alter it, using inline query,
Everything went fine by executing this query:
DECLARE @script AS NVARCHAR(MAX)
SET @script = 'ALTER PROCEDURE GetALL
with recompile
AS
BEGIN
SELECT *
FROM dbo.Main
INNER JOIN dbo.alabla ON dbo.Main.ID = dbo.ATTENDANCE.EMPLOYEE_ID
END'
EXEC sp_executesql @script ;
Above query has a syntax error alabla
, the table does not exists but EXEC sp_executesql @script ;
performed without any error.
and when I tried to use this stored procedure, I get an error:
Msg 208, Level 16, State 1, Procedure GetALL, Line 5
Invalid object name 'dbo.alabla'.
Can anybody tell here that how we make sure that inline query execution is safe?