Do you find T-SQL scripts hard to read with all the square brackets?
The T-SQL scripting tools (such as SQL Server Management Studio) provide two options for scripting names: either to quote them or to omit quotes.
If you avoid things like spaces in object names, you can mostly get away without quoting i.e.
Sales.Customers is just fine and doesn’t need to be [Sales].[Customers].
Even then, one problem that can arise is that a name you had used in your code could become a SQL reserved word. In that case, you either need to change every reference to it (painful), or quote it wherever it’s used (also painful). So quoting by default is always a safe option. However, it makes the scripts much harder to read due to visual noise.
What I feel is really needed is some way to determine if a name needs quoting i.e. a function such as:
ISVALIDASOBJECTNAME()
So for example:
ISVALIDASOBJECTNAME(‘Sales’) would return 1 but ISVALIDASOBJECTNAME(‘Sales Targets’) would return 0.
This functionality could then be used to extend the QUOTENAME function with an optional parameter that says:
QUOTENAME(‘Sales Targets’,0) for “always quote” or QUOTENAME(‘Sales Targets’,1) for “quote only if needed). They could leave 0 as the default so it is option and the function still works unchanged when no parameter is supplied.
That would then make it easy for the team to change SSMS to have a single setting for how you’d like scripts generated.
If you agree with this, please vote here: https://connect.microsoft.com/SQLServer/feedback/details/796172/isvalidasobjectname-and-quotename-enhancement-to-clean-up-script-readability
2013-08-03