Sqlserver-dba.com

SQL Server Database names with spaces

SQL Server Database names with spaces create problems for the DBA.During database creation leaving a database name blank or using / : * # ? " < > |  causes an error.

Creating a database name with a space , won’t throw an immediate error , but can cause application errors.

There are good reasons to not use spaces in database names.

1) Database names with spaces can confuse applications

An example is the following code:

EXEC( 'sp_msforeachdb''use ?; Select ''''?'''' DBName, Name FileNme,

fileproperty(Name,''''SpaceUsed'''') SpaceUsed from sysfiles''')

 If a space exists in the database name – the code will throw an error.

Database name space a 

To overcome the immediate error , I place square brackets [?] in the code. – to enclose the badly designed data element name

 EXEC( 'sp_msforeachdb''use [?]; Select ''''?'''' DBName, Name FileNme,

fileproperty(Name,''''SpaceUsed'''') SpaceUsed from sysfiles''')

Database name space b 
2) The iso-11179 rules outline naming conventions

Letters, Digits, Underscores.Read iso 11179-4 :Formulation of data definition for details.  Apply the iso-11179 rules to create a data dictionary usable across platforms  such as DB2, application levels integration and all programming languages.

3)Maintenance of database servers is less error-prone

If consistent naming conventions are used. My DBA scripts  execute across all database servers . As a fail-safe I use [] around database objects, but also run regular scans to capture objects with spaces.

Avoid Database names with spaces  for easier database server management

Author: Jack Vamvas (http://www.sqlserver-dba.com)

Author: Jack Vamvas (http://www.sqlserver-dba.com)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact