I've an issue where my query is throwing an error even though it is commented.
I didn't undertand why it is happening . I found this error code between my big query scripts where we are trying to execute everything in one shot .And also i tried of executing this commented script in seperate window but still showing me error meassage .Can anyone help me reason and soultion for this .thanks in advance .
/*
USE [MY_DATABASE]
GO
/*002458 -- End */
GO
/****** Object: Synonym [dbo].[SYN_BCM_POLICYINVOICE_D] Script Date: 2/1/2018 7:15:33 PM ******/
IF NOT EXISTS (select * from sys.synonyms where name='SYN_IM_ARCH_PREMIUMBATCH')
BEGIN
CREATE SYNONYM [dbo].[SYN_IM_ARCH_PREMIUMBATCH] FOR [VUEDATA_Billing].[dbo].[IM_ARCH_PREMIUMBATCH]
END
GO
*/
Error Message:
Msg 113, Level 15, State 1, Line 10 Missing end comment mark '/'. Msg
102, Level 15, State 1, Line 2 Incorrect syntax near ''.
Be careful when you use comment in SQLServer:
--
will only comment the line (but can be problematic if you unwrap the text in an other client language, where all the query may be commented)
/* */
will comment all the content between the open /*
and the FIRST closing */
after.
The line with /**** object: ... ***/
has a closing tag */
*/
at the end of the script throw an error because it tried to terminate comment wich is not open.
If you want a properly commented code I suggest to use /* */
on each functional block.
To finish, you also can just remove the automatic /**** object: ... ***/
line and the code will run perfectly (read: nothing will happen because its commented)
As you can see in the code formatting of your question, the comment is being closed by your line of /*002458 -- End */
. That's why the GO
is colored as it is. If you have this code in SSMS (or really any decent code editor) you should likewise see that the comment has been closed. Because of that your code is not commented out and then in addition you have the trailing */
at the end, which would also cause a syntax error.
When You comment code with /*
Commented_text */
the /*
and */
go in pairs. that means You have two blocks of commented code.
It looks like you wanted to comment all code seeing /*
at the start and */
at the end. But they don't work as nested. First start of comment ends when meets */
. So the last lane is not commented.