<p>I've noticed that Visual Studio 2008 is placing square brackets around column names in sql. Do the brackets offer any advantage? When I hand code T-SQL I've never bothered with them.</p>

<p>Example:</p>

<p>Visual Studio:</p>

<pre><code>SELECT [column1], [column2] etc...
</code></pre>

<p>My own way:</p>

<pre><code>SELECT column1, column2 etc...
</code></pre>

[{'answer_id': 52900, 'author': 'Torlack', 'author_id': 5243, 'author_profile': 'https://Stackoverflow.com/users/5243', 'pm_score': 3, 'selected': False, 'text': "<p>The brackets can be used when column names are reserved words.</p>\n\n<p>If you are programatically generating the SQL statement from a collection of column names you don't control, then you can avoid problems by always using the brackets.</p>\n"}, {'answer_id': 52901, 'author': 'Michael Haren', 'author_id': 29, 'author_profile': 'https://Stackoverflow.com/users/29', 'pm_score': 9, 'selected': True, 'text': "<p>The brackets are required if you use keywords or special chars in the column names or identifiers. You could name a column <code>[First Name]</code> (with a space) – but then you'd need to use brackets every time you referred to that column.</p>\n<p>The newer tools add them everywhere just in case or for consistency.</p>\n"}, {'answer_id': 52902, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Column names can contain characters and reserved words that will confuse the query execution engine, so placing brackets around them at all times prevents this from happening.  Easier than checking for an issue and then dealing with it, I guess.</p>\n'}, {'answer_id': 52905, 'author': 'Jeff Donnici', 'author_id': 821, 'author_profile': 'https://Stackoverflow.com/users/821', 'pm_score': 2, 'selected': False, 'text': "<p>I believe it adds them there for consistency... they're only required when you have a space or special character in the column name, but it's cleaner to just include them all the time when the IDE generates SQL.</p>\n"}, {'answer_id': 52910, 'author': 'Blorgbeard', 'author_id': 369, 'author_profile': 'https://Stackoverflow.com/users/369', 'pm_score': 6, 'selected': False, 'text': "<p>They're handy if your columns have the same names as SQL keywords, or have spaces in them.</p>\n\n<p>Example:</p>\n\n<pre><code>create table test ( id int, user varchar(20) )\n</code></pre>\n\n<p>Oh no! Incorrect syntax near the keyword 'user'.\nBut this:</p>\n\n<pre><code>create table test ( id int, [user] varchar(20) )\n</code></pre>\n\n<p>Works fine.</p>\n"}, {'answer_id': 52912, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': 4, 'selected': False, 'text': "<p>They are useful if you are (for some reason) using column names with certain characters for example.</p>\n\n<pre><code>Select First Name From People\n</code></pre>\n\n<p>would not work, but putting square brackets around the column name would work</p>\n\n<pre><code>Select [First Name] From People\n</code></pre>\n\n<p>In short, it's a way of explicitly declaring a object name; column, table, database, user or server.</p>\n"}, {'answer_id': 11163930, 'author': 'HSchlarb', 'author_id': 1475915, 'author_profile': 'https://Stackoverflow.com/users/1475915', 'pm_score': 2, 'selected': False, 'text': '<p>In addition\nSome Sharepoint databases contain hyphens in their names. Using square brackets in SQL Statements allow the names to be parsed correctly. </p>\n'}, {'answer_id': 33579501, 'author': 'Bill', 'author_id': 3516476, 'author_profile': 'https://Stackoverflow.com/users/3516476', 'pm_score': 3, 'selected': False, 'text': "<p>Regardless of following a naming convention that avoids using reserved words, Microsoft does add new reserved words. Using brackets allows your code to be upgraded to a new SQL Server version, without first needing to edit Microsoft's newly reserved words out of your client code. That editing can be a significant concern. It may cause your project to be prematurely retired....</p>\n\n<p>Brackets can also be useful when you want to Replace All in a script. If your batch contains a variable named @String and a column named [String], you can rename the column to [NewString], without renaming @String to @NewString. </p>\n"}, {'answer_id': 37642361, 'author': 'Lothar', 'author_id': 155082, 'author_profile': 'https://Stackoverflow.com/users/155082', 'pm_score': 3, 'selected': False, 'text': '<p>During the dark ages of SQL in the 1990s it was a good practice as the SQL designers were trying to add each word in the dictionary as keyword for endless avalanche of new features and they called it the SQL3 draft. </p>\n\n<p>So it keeps forward compatibility. </p>\n\n<p>And i found that it has another nice side effect, it helps a lot when you use  grep in code reviews and refactoring.</p>\n'}, {'answer_id': 65964158, 'author': 'zar', 'author_id': 841330, 'author_profile': 'https://Stackoverflow.com/users/841330', 'pm_score': 2, 'selected': False, 'text': '<p>They are useful to identify each elements in SQL.</p>\n<p>For example:</p>\n<pre><code>CREATE TABLE SchemaName.TableName (\n</code></pre>\n<p>This would actually create a table by the name <code>SchemaName.TableName</code> under default <code>dbo</code> schema even though the intention might be to create the table inside the <code>SchemaName</code> schema.</p>\n<p>The correct way would be the following:</p>\n<pre><code>CREATE TABLE [SchemaName].[TableName] (\n</code></pre>\n<p>Now it it knows what is the table name and in which schema should it be created in (rightly in the <code>SchemaName</code> schema and not in the default <code>dbo</code> schema)</p>\n'}]
['https://Stackoverflow.com/questions/52898', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5433/']