SQL Select Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Panosh

    SQL Select Question

    Hello,

    This is probably a stupid question but I am going to ask it anyway because I
    don't know the answer to it. Both SQL Select Statements, below, execute and
    retuurn the same results. Why would on put the [ around the table and
    column names?

    SELECT Customer.FirstN ame FROM Customer
    or
    SELECT [Customer].[FirstName] FROM [Customer]


    Thanks,
    Rob Panosh



  • Makjalele

    #2
    Re: SQL Select Question


    brackets are used when table/column names contain spaces or keywords.in
    other cases brackets may be used also but also could be avoided.


    "Rob Panosh" <rob_!!!NO!!!SP AM!!!_panosh@as dsoftadfdware.c om> wrote in
    message news:3fd716b0@n ews.splitrock.n et...[color=blue]
    > Hello,
    >
    > This is probably a stupid question but I am going to ask it anyway because[/color]
    I[color=blue]
    > don't know the answer to it. Both SQL Select Statements, below, execute[/color]
    and[color=blue]
    > retuurn the same results. Why would on put the [ around the table and
    > column names?
    >
    > SELECT Customer.FirstN ame FROM Customer
    > or
    > SELECT [Customer].[FirstName] FROM [Customer]
    >
    >
    > Thanks,
    > Rob Panosh
    >
    >
    >[/color]


    Comment

    • David Portas

      #3
      Re: SQL Select Question

      See the following topic from Books Online:
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


      In your example the delimiters are not essential since the names don't
      include special characters or reserved words. However, using the delimiters
      protects your code against the possibility that a name used as an identifier
      may be declared a reserved word in a future version of SQL Server. That's
      not likely for words like "Customer" but in the interests of a common style
      and good programming practice this style may be adopted for all identifiers.
      As with any aspect of coding style, different developers have different
      preferences and practices.

      The ANSI standard delimiter is to use double quotes which works in TSQL
      assuming the QUOTED_IDENTIFI ER option is ON. [] is an alternative notation
      used in Access and SQLServer.

      --
      David Portas
      ------------
      Please reply only to the newsgroup
      --


      Comment

      • Rob Panosh

        #4
        Re: SQL Select Question

        David,

        Thank you for the explanation.

        Rob

        "David Portas" <REMOVE_BEFORE_ REPLYING_dporta s@acm.org> wrote in message
        news:gaudnT1_Da I0ikqiRVn-iw@giganews.com ...[color=blue]
        > See the following topic from Books Online:
        > http://msdn.microsoft.com/library/en...on_03_6e9e.asp
        >
        > In your example the delimiters are not essential since the names don't
        > include special characters or reserved words. However, using the[/color]
        delimiters[color=blue]
        > protects your code against the possibility that a name used as an[/color]
        identifier[color=blue]
        > may be declared a reserved word in a future version of SQL Server. That's
        > not likely for words like "Customer" but in the interests of a common[/color]
        style[color=blue]
        > and good programming practice this style may be adopted for all[/color]
        identifiers.[color=blue]
        > As with any aspect of coding style, different developers have different
        > preferences and practices.
        >
        > The ANSI standard delimiter is to use double quotes which works in TSQL
        > assuming the QUOTED_IDENTIFI ER option is ON. [] is an alternative notation
        > used in Access and SQLServer.
        >
        > --
        > David Portas
        > ------------
        > Please reply only to the newsgroup
        > --
        >
        >[/color]


        Comment

        • Rob Panosh

          #5
          Re: SQL Select Question

          Makjalele,

          Thanks ....

          Rob

          "Makjalele" <stupidaria_dom estica@net.hr> wrote in message
          news:br7400$ngv $1@ls219.htnet. hr...[color=blue]
          >
          > brackets are used when table/column names contain spaces or keywords.in
          > other cases brackets may be used also but also could be avoided.
          >
          >
          > "Rob Panosh" <rob_!!!NO!!!SP AM!!!_panosh@as dsoftadfdware.c om> wrote in
          > message news:3fd716b0@n ews.splitrock.n et...[color=green]
          > > Hello,
          > >
          > > This is probably a stupid question but I am going to ask it anyway[/color][/color]
          because[color=blue]
          > I[color=green]
          > > don't know the answer to it. Both SQL Select Statements, below, execute[/color]
          > and[color=green]
          > > retuurn the same results. Why would on put the [ around the table and
          > > column names?
          > >
          > > SELECT Customer.FirstN ame FROM Customer
          > > or
          > > SELECT [Customer].[FirstName] FROM [Customer]
          > >
          > >
          > > Thanks,
          > > Rob Panosh
          > >
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...