Question of the month April 2015 – Why is extra comma giving error for table variable and not for temporary table?

Consider the following statement

CREATE TABLE #T (I INT,)

It will get executed without error

But when you use table variable as shown below

DECLARE @T TABLE(I INT,)

You get the following error

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.

Why is extra comma giving error for table variable and not for temporary table?

Advertisements

6 thoughts on “Question of the month April 2015 – Why is extra comma giving error for table variable and not for temporary table?

  1. This is a very old bug in SQL server. As long as the impact wass not high, MS have rated this bug as Minor category. One other reason would be, they dont want to break the codes in the production by changing the behaviour as well(if at all someone coded).

    When MS introduced the table varaible (I think in SQL Server 2000), MS have taken care/corrected this issue.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s