Legal/illegal characters in table name

  • MyDoggieJessie (4/7/2015)


    This assumes that you have a schema in the database named "tmp" otherwise it fails because the schema does not exist.

    I agree, I supposed it was a trick: you notice that the name is valid and you do not note that schema is not.

  • It should have been possible to attempt an answer without just running the code. And, given the title of the question, it should have been clear that the "tmp" error was just an oversight and not really relevant.

  • Richard Warr (4/8/2015)


    It should have been possible to attempt an answer without just running the code. And, given the title of the question, it should have been clear that the "tmp" error was just an oversight and not really relevant.

    Only if you notice the question title! I always answer via the email, which doesn't include the title. And having read the question in the email, when I click the link my eyes go straight to the answers 🙂

  • This could have been a nice question about an interesting curiosity (though utterly useless, as nobody will ever use this in real life - right?).

    Unfortunately, the mishap with the schema name ruins the question. I immediately saw that the correct answer depends on an assumption about the tmp schema, and while pondering which assumption to make noticed the question title. This still didn't convince me fully (there have in the past been questions with very misleading titles), but it did give me enough confidence to assume that the author has a tmp schema and has forgotten that not everyone has.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • The table is not created. The question did not mention anything about the tmp schema existing.

    This will fail with an error.

    Msg 2760, Level 16, State 1, Line 1

    The specified schema name "tmp" either does not exist or you do not have permission to use it.

  • MyDoggieJessie (4/7/2015)


    This assumes that you have a schema in the database named "tmp" otherwise it fails because the schema does not exist.

    As pointed out.

  • If only the code had been

    declare @sql nvarchar(max)

    set @sql = 'IF OBJECT_ID(''TempDB..[' + CHAR(31) + ']'') IS NOT NULL DROP TABLE TempDB..[' + CHAR(31) + ']' + CHAR(10) +

    'create table tempdb..[' + char(31) + ']

    (

    id int

    )'

    EXECUTE sp_executesql @sql

  • Given the title of the question, I figured the tmp schema was an oversight. After changing the schema to dbo, I found the results simple enough. From there, try to do anything else with the table...interesting.

  • MyDoggieJessie (4/7/2015)


    This assumes that you have a schema in the database named "tmp" otherwise it fails because the schema does not exist.

    Agree

  • MyDoggieJessie (4/7/2015)


    This assumes that you have a schema in the database named "tmp" otherwise it fails because the schema does not exist.

    and again...+1

    Another incorrect correct answer. TEST BEFORE POST. 😀

  • I got it wrong. So I tested it. It failed. Hmmmm.

  • MyDoggieJessie (4/7/2015)


    This assumes that you have a schema in the database named "tmp" otherwise it fails because the schema does not exist.

    Oh, that's why it failed. Thanks for the help.

  • Koen Verbeeck (4/8/2015)


    Nice question, but a bit of an oversight on the tmp schema.

    I totally agree.

  • free_mascot (4/8/2015)


    Carlo Romagnano (4/8/2015)


    MyDoggieJessie (4/7/2015)


    This assumes that you have a schema in the database named "tmp" otherwise it fails because the schema does not exist.

    +1

    Ahi, ahi, ahi, ahi, ahi, ahi!!!!!!!!!!

    :w00t:

    +1

    +1

  • Sean of the Lynchmob (4/8/2015)


    I got this when I ran it:

    Msg 2760, Level 16, State 1, Line 1

    The specified schema name "tmp" either does not exist or you do not have permission to use it.

    .....and no table created. So I have to disagree with the "correct" answer.....

    +1

Viewing 15 posts - 16 through 30 (of 52 total)

You must be logged in to reply to this topic. Login to reply