none
Characters that are not allowed in table name & column name in sql server ?

    Question

  • can any one tell me which characters are not allowed in table name & column name in sql server ?
    Tuesday, November 23, 2010 10:07 AM

Answers

  • Hi Sahil, you are correct... .. It is possible to use the above characters in Table name and Column Name using SSMS/TSQL square brackets..

    The Common rules:
    Rules for Regular Identifiers

    The rules for the format of regular identifiers depend on the database compatibility level. This level can be set by using ALTER DATABASE . When the compatibility level is 100 , the following rules apply:

    1. The first character must be one of the following:

      • A letter as defined by the Unicode Standard 3.2. The Unicode definition of letters includes Latin characters from a through z, from A through Z, and also letter characters from other languages.

      • The underscore (_), at sign (@), or number sign (#).

        Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts with the at sign always denotes a local variable or parameter and cannot be used as the name of any other type of object. An identifier that starts with a number sign denotes a temporary table or procedure. An identifier that starts with double number signs (##) denotes a global temporary object. Although the number sign or double number sign characters can be used to begin the names of other types of objects, we do not recommend this practice.

        Some Transact-SQL functions have names that start with double at signs (@@). To avoid confusion with these functions, you should not use names that start with @@.

    2. Subsequent characters can include the following:

      • Letters as defined in the Unicode Standard 3.2.

      • Decimal numbers from either Basic Latin or other national scripts.

      • The at sign, dollar sign ($), number sign, or underscore.

    3. The identifier must not be a Transact-SQL reserved word. SQL Server reserves both the uppercase and lowercase versions of reserved words.

    4. Embedded spaces or special characters are not allowed.

    5. Supplementary characters are not allowed.

    When identifiers are used in Transact-SQL statements, the identifiers that do not comply with these rules must be delimited by double quotation marks or brackets.

    Hope this help you Sahil

    thanks....


    - M S (We are what we repeatedly do, Excellence, then, is not an act, but a habit.)
    • Marked as answer by Tom Li - MSFT Wednesday, December 01, 2010 9:26 AM
    Tuesday, November 23, 2010 10:56 AM
  • We had a similar thread a while ago regarding characters that allowed in table name & column name.  Check sysname topic in BOL.

    You may also want to review this blog 

    Do not use spaces or other invalid characters in your column names
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by Tom Li - MSFT Wednesday, December 01, 2010 9:26 AM
    Tuesday, November 30, 2010 8:44 PM
    Answerer

All replies

  • Some of many

     %^&({}+-/ ]['''

    create

     

     

    create table 1 --failed

     

     


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/

     

    table [1] --ok
    Tuesday, November 23, 2010 10:17 AM
    Moderator
  • thanks for your reply.

    I tried all these characters & sql server allowed these characters in both table name & column name.

    just for your information that i am using sql server 2005.

     

    Tuesday, November 23, 2010 10:29 AM
  • Really

    CREATE

     

    TABLE t% (c int)  --failed

    CREATE

     

    TABLE % (c int) --failed

    It creates the table only if  you wrap it with the bracketes

    CREATE

     

    TABLE [t%] (c int)


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Tuesday, November 23, 2010 10:41 AM
    Moderator
  • oh......

    i was wrapping the names in square brackets. that was why it was allowing...

    one more thing i want to know is that if i wrap the name in brackets, then all characters are allowed or still some are not allowed (if not allowed then specify such characters) ?

    Tuesday, November 23, 2010 10:45 AM
  • Hi Sahil, you are correct... .. It is possible to use the above characters in Table name and Column Name using SSMS/TSQL square brackets..

    The Common rules:
    Rules for Regular Identifiers

    The rules for the format of regular identifiers depend on the database compatibility level. This level can be set by using ALTER DATABASE . When the compatibility level is 100 , the following rules apply:

    1. The first character must be one of the following:

      • A letter as defined by the Unicode Standard 3.2. The Unicode definition of letters includes Latin characters from a through z, from A through Z, and also letter characters from other languages.

      • The underscore (_), at sign (@), or number sign (#).

        Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts with the at sign always denotes a local variable or parameter and cannot be used as the name of any other type of object. An identifier that starts with a number sign denotes a temporary table or procedure. An identifier that starts with double number signs (##) denotes a global temporary object. Although the number sign or double number sign characters can be used to begin the names of other types of objects, we do not recommend this practice.

        Some Transact-SQL functions have names that start with double at signs (@@). To avoid confusion with these functions, you should not use names that start with @@.

    2. Subsequent characters can include the following:

      • Letters as defined in the Unicode Standard 3.2.

      • Decimal numbers from either Basic Latin or other national scripts.

      • The at sign, dollar sign ($), number sign, or underscore.

    3. The identifier must not be a Transact-SQL reserved word. SQL Server reserves both the uppercase and lowercase versions of reserved words.

    4. Embedded spaces or special characters are not allowed.

    5. Supplementary characters are not allowed.

    When identifiers are used in Transact-SQL statements, the identifiers that do not comply with these rules must be delimited by double quotation marks or brackets.

    Hope this help you Sahil

    thanks....


    - M S (We are what we repeatedly do, Excellence, then, is not an act, but a habit.)
    • Marked as answer by Tom Li - MSFT Wednesday, December 01, 2010 9:26 AM
    Tuesday, November 23, 2010 10:56 AM
  • As a general rule when determining a standard naming convention for database objects you would not want to use any special charactors. The '_' is common, old legacy systems use '-' but these should be the only exceptions. I prefer verbose camal case with class words and abbreviations used only for class words with a few exceptions.
    Tuesday, November 30, 2010 8:32 PM
  • We had a similar thread a while ago regarding characters that allowed in table name & column name.  Check sysname topic in BOL.

    You may also want to review this blog 

    Do not use spaces or other invalid characters in your column names
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by Tom Li - MSFT Wednesday, December 01, 2010 9:26 AM
    Tuesday, November 30, 2010 8:44 PM
    Answerer