Kira
Kira

Reputation: 975

Variable names in SQL Server

Can I declare name of SQL Server variable in a table with spaces?

create table test(
record name, float, not null
.....

The above query when executed gives me an error. Is there any way to declare the variable as variable name with a space..??

Upvotes: 0

Views: 2483

Answers (3)

Chris
Chris

Reputation: 2952

use [square brackets] around your column names with spaces and you should be fine.

It would be advisable in the long term to avoid spaces all together if you can, it will save you hours of stress in the future.

Upvotes: 0

Lucian
Lucian

Reputation: 4001

Try using square brackets:

create table test(
[record name] float not null)

Upvotes: 1

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79969

Yes, escape these names using []:

[record name] ....

These names are called Delimited identifiers:

Are enclosed in double quotation marks (") or brackets ([ ]).

But it is not recommended, use legal names instead or regular identifiers.

Upvotes: 8

Related Questions