0

is it need to put ';' a semicolon in front of a CTE? would any one have that idea?

Thank you for the replays.........

OMG Ponies
  • 314,254
  • 77
  • 507
  • 490
jesvin
  • 55
  • 2
  • 13
  • This is TSQL only -- Oracle terminates every command with a semicolon, so there's no need. I assume PostgreSQL handles things similar to Oracle... – OMG Ponies Dec 22 '10 at 06:45
  • When should I use semicolons in SQL Server?: http://stackoverflow.com/questions/710683/when-should-i-use-semicolons-in-sql-server – Mitch Wheat Dec 22 '10 at 07:06

1 Answers1

4

Only if the previous statement does not end in ;

I don't personally because I use ; on the end of my statements.

When I answer here on SO, I do for clarity.

"WITH" itself can be used in many places so the ; is needed to enable the parser to determine the WITH context correctly (CTE link)

A contrived example: where is the statement delimiter?

ALTER DATABASE foo SET OFFLINE WITH ROLLBACK IMMEDIATE SELECT * FROM bar

ALTER DATABASE foo SET OFFLINE WITH MYCTE AS (SELECT * FROM bar) SELECT * FROM MYCTE

The same applies to DROP ASSEMBLY or EXECUTE or RECONFIGURE or MERGE

onedaywhen
  • 53,058
  • 12
  • 94
  • 134
gbn
  • 408,740
  • 77
  • 567
  • 659