SQL Server Tip : . Where to use SQURE Bracket around table name?

Have you ever thought, what if your table name

1. Is exactly as of SQL Server keyword

2. Is having space in between like Student Fav Actor

If you go ahead and query against table Student Fav Actor like below, most likely you will get error message as below,

clip_image001

There may me one more scenario where table name is something like FROM. If you query in usual way, obviously you will be getting expected error message.

clip_image002

So how to query table named [However this is wrong practice to put spaces and use SQL Server keyword as table name] like above?

Very simple is the solution, put table name in square brackets.

clip_image004

You might encounter columns name of table are having spaces or named as keywords. In that case also you need to apply square bracket with that particular column name to work with.

One thought on “SQL Server Tip : . Where to use SQURE Bracket around table name?

  1. Pingback: Monthly Report July 2011: Total Posts 16 « debug mode……

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s