27 June,2011 by Tom Collins
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.
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.
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''')
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.
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)
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |