How to write comments in SQL?

Spread the love

Writing Comments in SQL –

There could be many reasons why do you want to write comments in SQL. Writing comments only helps others to understand what are you trying to do but it also help you when you look at the query after a long time.

There are various ways to write comments in SQL. Let’s see how to write them.

To write an inline comment, we use double hyphens like this

-- Get Everything from city
SELECT * 
FROM city;

You can also use # symbol to write an inline comment although this is less used.

# Get Everything from city
SELECT * 
FROM city;

You can also write multi line comments in SQL.

/* 
Get Name, and Population
from city table
*/
SELECT 
	Name,
	Population
FROM city;

/* starts a comment and */ end a comment. Anything between them is a comment.

Leave a Reply