Error While Creating a table

  • Hi Everyone,

    I have a T-sql to show you which throws an error when we run it.Please help in understanding the problem here and provide the solution .Below is the t-sql which throws an error :

    CREATE TABLE QCHECK([Access Chapter 1 Big Name [ment]] VARCHAR(100))

    Regards

    Chaithanya M

  • How about this?

    CREATE TABLE QCHECK([Access Chapter 1 Big Name [ment]]] VARCHAR(100))



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • Hi,

    thanks fore reply.Could you please expalain how this worked by adding a ']'. How does sql server treat this ?

    Regards

    Chaithanya M

  • If you want Access Chapter 1 Big Name [ment] as your column name, the below query should give you the exact way to represent your column name in the table definition

    SELECT QUOTENAME('Access Chapter 1 Big Name [ment]')

    You will have to add 2 closing brackets for 1 opening bracket inside your main opening/closing bracket.

    Sounds confusing, right!! Try some combinations with the query provided, you will understand.


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Hi,

    SQL Server allows any character in the current code page to be used in a delimited identifier. For example, you can create a table with the name Employee], where the closing square bracket is part of the name. To do this you have to escape the closing square bracket with two more square brackets as shown in the above example by okbangas.

    Regards,
    Ravi.

  • My advice is to save yourself a world of pain, and restrict names of databases, objects, columns etc to alphanumeric characters and underscores.

    John

Viewing 6 posts - 1 through 5 (of 5 total)

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