Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Question of the month December 2012 - Why is last comma ignored in CREATE TABLE statement?

Dec 12 2012 12:00AM by Madhivanan   

Consider the following CREATE TABLE statements

CREATE TABLE emp1(emp_id int,)
GO
CREATE TABLE emp2(emp_id int,first_name varchar(50),)
GO

Note that there is extra comma after the datatype of last column. But SQL Server ignores it and execute them without last comma. Why is last comma ignored in this case?

Tags: 


Madhivanan
3 · 40% · 12862
7
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

9  Comments  

  • as Sql server create tabel syntex after last comma CONSTRAINTS are placed , in case there is no information provided to sql it assumes there no key define.

    commented on Dec 12 2012 4:35AM
    sumit.kanugo
    2009 · 0% · 8
  • I have noticed this before as well. Checked the "BNF" in BOL and that one is certainly correct as in that it doesn't cater for a trailing comma. So please, enlighten us why this is silently ignored?

    commented on Dec 12 2012 5:58AM
    Jan Van der Eecken
    2346 · 0% · 5
  • HI Madhivan,

    Its quite interesting and sweet like you.can u please explain???

    Thanks in advance.

    commented on Dec 12 2012 7:04AM
    Bala Krishna
    83 · 2% · 678
  • Extra comma after last column is allowed because it makes code easier to maintain. The same approach we can see in programming languages. For example, in C# when you use object or collection initializers, you can also use extra comma:

    List<int> digits = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, };
    
    commented on Dec 12 2012 10:42PM
    Olga Medvedeva
    66 · 3% · 896
  • Olga,

    You say 'it makes code easier ot maintain'. How is that? Area we talking about a single click of some sort or not having to press the backspace key?

    All I know is that whenever I pivot vertical items into a horizontal list using xml path('') I always bend over backwards trying to remove that extra comma at the end. Maybe the people at Microsoft noticed that and decided to ignore all trailing commas as a principle. Ha ha!! :-)

    commented on Dec 13 2012 1:12AM
    dishdy
    16 · 10% · 3269
  • dishy,

    Under "easier to maintain" I meant that, for example, if you want to add/delete some value to array (in case of collection initializer) or some field/property of a class (object initializer) or some value to enum, you can just add/remove/comment out just one line. For example, you have enum WorkingDays and you want to remove Saturday from that list, you can just comment out (or remove) last line without removing comma from previous line:

    public enum WorkingDays
    {
               Monday,
               Tuesday,
               Wednesday,
               Thursday,
               Friday,
               //Saturday
    }
    

    And this behaviour for array-initializers goes from C# language specification: "Like Standard C++, C# allows a trailing comma at the end of an array-initializer. This syntax provides flexibility in adding or deleting members from such a list, and simplifies machine generation of such lists."

    So I think that SQL Server has the same reasons to ignore trailing commas.

    commented on Dec 13 2012 2:12AM
    Olga Medvedeva
    66 · 3% · 896
  • @Olga Medvedeva if it was that way, it should also allow for optional comma in SELECT list, where it would be extremely useful:

    SELECT
      col1,
      col2,
      --col3
    FROM source
    

    or

    SELECT
      --col1
      ,col2
      ,col3
    FROM source
    

    To me it's just a parser or spec bug. Take care :-)

    commented on Dec 14 2012 5:31AM
    chojrak11
    1023 · 0% · 25
  • It really helps maintaining code especially when design changes reorder the rows or you temporarily want to remove a row.

    However, the benefit only comes in action when you use the syntax with one column per row, i.e.

    create table a (
     firstrow varchar(50),
    secondrow varchar(50),
    timestamp datetime,
    )
    

    if you use a single line code, you will gain nothing, as commenting out parts of a code line is something you should not do on a regular basis. For me, thats perfect, especially in select clauses where I can comment in and out columns (e.g. those that are only relevant for the customer, but not for my tests).

    commented on Dec 14 2012 5:56AM
    Guenter
    28 · 6% · 1887
  • To analyse a reason for such behaviour, I have tried to use native DOM parser and see how it be processed. I have realized, that comma is included into statement ColumnDefinition. I think comma is kind of split char separator (last empty element is ignored and it is absent after parsing). SELECT has different behaviour because it is SelectColumn statement and probably has different parsing logic.

    commented on Dec 20 2012 3:10PM
    Dubelewskyj Oleksandr
    475 · 0% · 81

Your Comment


Sign Up or Login to post a comment.

"Question of the month December 2012 - Why is last comma ignored in CREATE TABLE statement?" rated 5 out of 5 by 7 readers
Question of the month December 2012 - Why is last comma ignored in CREATE TABLE statement? , 5.0 out of 5 based on 7 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]