bgs
bgs

Reputation: 3213

Table column name create with empty space auto formating , why..?

I have create the column with name " Departure _Date " , but it is automatically changed into " [Departure _Date] "(Not in query using SQL Server Management studio). If i remove the empty space from the column name , there is no problem. Anyone can explain detailed..

Upvotes: 1

Views: 837

Answers (1)

Justin Crabtree
Justin Crabtree

Reputation: 327

Square brackets around column names are inferred. Even when you cannot see them they are always really there.

When using spaces in column names and certain keywords it's necessary to use square brackets more frequently when referring to columns, including in table generation scripts and the design interface.

SELECT Departure _Date FROM myTable

For example, without the square brackets, this SQL statement would be selecting the "Departure" field and returning it with an alias of "_Date".

Even when using the column name Departure_Date, the column could be referred to as either [Departure_Date] or Departure_Date in SQL statements.

Upvotes: 3

Related Questions