N
N
Nikita072021-03-10 14:28:27
Transact SQL
Nikita07, 2021-03-10 14:28:27

How to understand what is written here?

Help me figure out the SQL query, I can’t understand why quadrant brackets are needed, i.e. why are they even needed in the example and T-SQL in general?

SELECT TOP (10) [M].[membershipId]
FROM Membership AS [m]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-03-10
@Nikita07

The parentheses are required if you use keywords or special characters in column names or identifiers. You can name the column [First Name] (with a space) - but then you will need to use parentheses every time you refer to that column. Otherwise, square brackets are optional.
For example, your request could be written like this:

SELECT TOP (10) m.membershipId FROM Membership AS m;

but
SELECT TOP (10) m.[Member Name] FROM [Service Membership] AS m;

MS SQL fiddle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question