What characters are valid in an SQL Server database name?

后端 未结 4 1840
执笔经年
执笔经年 2020-12-08 09:15

We\'re going to provide our clients with a tool that (among other things) creates a new SQL Server database, and I want to be able to do basic validation on the database nam

4条回答
  •  天涯浪人
    2020-12-08 09:56

    There is a difference between regular identifiers and delimited identifiers. A regular identifier is bound by the limitations that you mention, while a delimited identifier can contain any characters (except the delimiter).

    As you are using quotation marks around the identifier, it's a delimited identifier, and you are not limited by the rules of regular identifiers.

    Without the delimiters you can only create databases with identifiers that follow the rules of regular identifiers:

    create database db_name
    

    With delimiters, you can use pretty much anything:

    create database "That's a funny name, isn't it?"
    
    create database [)(/%Q)/#&%¤)Q/#)!]
    

提交回复
热议问题