Therefore, the nested comment should have a corresponding block closed(/*) comment mark. For example, if you specify the block open (/*) in existing comments, SQL Server treats it as a nested comment. We can have nested comments in SQL Server. If any developer scripts out stored procedure later, he can see brief information on who and what was modified. For example, the below script adds the object information, script date, author, description on the stored procedure script. You can also use these multi-line comments for displaying useful information about the script. SQL Server ignores the texts, code written inside these. Therefore, SQL Server uses multi-line comments that start with /* and ends with */. It is not a feasible solution if we want to comment out multiple lines of code. If we need to comment out multiple lines, you need to put a double dash on each line. If we comment using the double dash /(–), SQL Server considers it for a single line. Similarly, you can click on the highlighted icon to remove the single-line comment. You can also use shortcut keys CTRL +K CTRL+C for putting out comments quickly. If you select multiple lines and click on the comment out icon, it adds double dashes on each line, as shown below. It puts double dashes in front of the line. Select the line and click on the highlighted icon in SSMS. The SQL Server Management Studio has an icon to add the double dashes for commenting out a single line character. Therefore, you do not see it in the query output. In the below example, we commented on the column in the select statement. The SSMS IDE changed the text color to green, and SQL Server skips executing this piece of code. Īnother example shows I comment out a single line of code using the double dashes. You can also see a different color in SQL Server Management Studio (SSMS) after you commented on a piece of code.įor example, here, we add a comment in the script to highlight the purpose of the query.įROM. Once you add the two dashes, SQL Server ignores the text written after these dashes in a single line. The single line SQL comment uses two dashes (–) in SQL Server. SQL Comments can be added in the following formats. You can add comments between the keywords, parameters at the beginning or end of a statement. Therefore, put a comment on where the block and SQL Server skips execution. For example, suppose you do not want to execute the where block condition in a select statement. SQL Server does not execute these comments, and it does not affect query behavior as well.Īnother purpose of the SQL comment is to disable the execution of a specific code. For example, you can put a comment that showcases the purpose of the statement, such as adding a specific query hint or modifying script logic. The SQL comments in a statement help you to read and maintain the SQL scripts easily. Also, multiple developers change the T-SQL, and it becomes difficult to track who altered the code and for what reason. In a typical database, we have multi lines or page SQL statements in a view, SQL statement or the stored procedure.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |