Correct syntax for table variable names containing a space

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

    Correct syntax for table variable names containing a space

    Hello again ;-)

    What is the correct syntax to use when inserting a value into a table that
    contains a variable name with spaces.

    This works

    $query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

    And this does not

    $query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"

    Regards
    Dynamo

  • Gary L. Burnore

    #2
    Re: Correct syntax for table variable names containing a space

    On 22 Nov 2004 07:50:30 -0800, Dynamo <Dynamo_member@ newsguy.com>
    wrote:
    [color=blue]
    >Hello again ;-)
    >
    >What is the correct syntax to use when inserting a value into a table that
    >contains a variable name with spaces.
    >
    >This works
    >
    >$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"
    >
    >And this does not
    >
    >$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"[/color]

    I'd suggest simply correcting the problem by NOT putting spaces in
    such things as field names.



    --
    gburnore@databa six dot com
    ---------------------------------------------------------------------------
    How you look depends on where you go.
    ---------------------------------------------------------------------------
    Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
    | ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
    Black Helicopter Repair Svcs Division | Official Proof of Purchase
    =============== =============== =============== =============== ===============
    Want one? GET one! http://signup.databasix.com
    =============== =============== =============== =============== ===============

    Comment

    • Steve

      #3
      Re: Correct syntax for table variable names containing a space


      (1) Don't do that.
      (2) If you must, use backticks (`) around the offending column name:

      $query = "INSERT INTO Catalogue (`Book title`) VALUES ('The Crow')";
      ---
      Steve

      Comment

      • Michael Fesser

        #4
        Re: Correct syntax for table variable names containing a space

        .oO(Dynamo)
        [color=blue]
        >What is the correct syntax to use when inserting a value into a table that
        >contains a variable name with spaces.[/color]



        Micha

        Comment

        • Andy Hassall

          #5
          Re: Correct syntax for table variable names containing a space

          On 22 Nov 2004 07:50:30 -0800, Dynamo <Dynamo_member@ newsguy.com> wrote:
          [color=blue]
          >Hello again ;-)
          >
          >What is the correct syntax to use when inserting a value into a table that
          >contains a variable name with spaces.
          >
          >This works
          >
          >$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"
          >
          >And this does not
          >
          >$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"[/color]

          RENAME would be a good idea... spaces in a table name is a particularly bad
          idea.

          If you insist on keeping it, then double quotes are the standard method, to
          produce a "quoted identifier".

          $query = "INSERT INTO Catalogue (\"Book title\") VALUES ('The Crow')"

          Specific databases may have alternatives, or not accept the standard
          identifier quoting method, however you didn't state what database you're using.

          (But anyway... rename the table... really).

          --
          Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
          <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

          Comment

          • Chung Leong

            #6
            Re: Correct syntax for table variable names containing a space

            Try putting the name in square brackets.


            "Dynamo" <Dynamo_member@ newsguy.com> wrote in message
            news:cnt1s602g8 g@drn.newsguy.c om...[color=blue]
            > Hello again ;-)
            >
            > What is the correct syntax to use when inserting a value into a table that
            > contains a variable name with spaces.
            >
            > This works
            >
            > $query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"
            >
            > And this does not
            >
            > $query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"
            >
            > Regards
            > Dynamo
            >[/color]


            Comment

            Working...