emihir0
emihir0

Reputation: 1250

[table].[field] vs table.field difference?

I don't quite understand the difference between, for example:

SELECT [Products].[ID], [Products].[ProductName] FROM Products ORDER BY [ProductName]; 

compared with

SELECT Products.ID, Products.ProductName FROM Products ORDER BY ProductName; 

Can someone give me some insight please? The query produces same result for me.

Upvotes: 1

Views: 162

Answers (2)

Krish
Krish

Reputation: 5917

In a programming language a variable name must be unique throughout its context and cannot have Spaces.

VariableA is valid
variable b is not valid
variable_b is valid

Some languages are even case sensitive.

variableA is valid
VariableA is valid and different from variableA

On the other hand MS ACCESS allows free formatted names for it tables, queries, forms etc. This means you could have a table called

This is a fruit table

to identify "this is a fruit table" as one word/item Access somehow needs to evaluate/know that the variable name is one word or its a variable name and not a text. Therefore Access uses [] to encapsulate the word so it can evaluate its content.

if you follow a most desired coding style you would name your tables with prefix such as tbl_fruits, frm_fruits, qry_view_fruits which will help you as well as Access to understand what you are referring to.

Upvotes: 3

juergen d
juergen d

Reputation: 204784

If you use brackets around the names you can use reserved words like order for a table or colum name or names with spaces and such.

But you only need to apply the brackets on those but can apply it on all if you like.

Upvotes: 1

Related Questions