Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why SQL Server doesn't treat this code erratic?

Tags:

sql-server

It not actually a problem that i'm facing. But i'm just wondering that the first line in the code written below should be treated as a syntax error by SQL Server because of the extra comma (,) in the end of columns list. But it runs the code fine. Does anyone know the reason?

CREATE TABLE #TEMP(COL1 INT,COL2 VARCHAR,)    
INSERT INTO #TEMP VALUES (1,'A')    
SELECT * FROM #TEMP    
DROP TABLE #TEMP
like image 727
Captain Jack Sparrow Avatar asked Jun 28 '12 09:06

Captain Jack Sparrow


1 Answers

It should be flagged as a syntax error, but there is a bug in SQL Server that doesn't treat the trailing comma as a syntax error.

Source: Microsoft Support (The affected versions in the list - 6, 6.5, and 2000 - are old, but I guess it's still around because it just worked for me in 2008.)

like image 72
TeeJay Green Avatar answered Nov 18 '22 16:11

TeeJay Green