I'm working on some legacy SQL and the author delimited every column name and data type declaration. See the following:
CREATE TABLE SomeTable ( [SomeDate] [datetime] NOT NULL, [SomeInt] [int] NOT NULL, [SomeString] [nvarchar] NOT NULL ) ON [PRIMARY] GO
Is this considered a best-practice when writing T-SQL for SQL Server? Since I'm now maintaining this code, should I continue the practice?
I personally would only write that if you're using reserved keywords as column/table names, which you shouldn't be anyway. Personally I think otherwise, it makes the SQL code less 'clean' and a bit more difficult to read.
This style is usually what is generated by SQL tools, as it guarantees that there won't be any issues with reserved word conflicts.
If the name of the table or column is "harmless" like "SomeInt", then the square brackets [...]
aren't required - you can specify them, if you want to, don't have to.
On the other hand - always using those will make sure that even "dangerous" column names like '[Message]'
and others, or column names with spaces in them like [Product Name]
, will always be handled correctly.
So - you don't have to continue doing it, but I would think it's a good practice and if it's already been used, I'd recommend to keep using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With