0

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..??

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ok but i uploaded excel files into the server and those have spaces . Its either this or renaming many records. Thanks...
1

Try using square brackets:

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.