I am pretty novice in writing SQL but would like to get better. One of the things that I have never really understood is how to interpret the construct syntax for any give object. Here is an example of OPENROWSET definition taken from https://msdn.microsoft.com/en-us/library/ms190312.aspx. I understand the pipe "|" represents "OR" but not sure about the other tags. Is there a good place to learn how to interpret this?
OPENROWSET
( { 'provider_name' , { 'datasource' ; 'user_id' ; 'password'
| 'provider_string' }
, { [ catalog. ] [ schema. ] object
| 'query'
}
| BULK 'data_file' ,
{ FORMATFILE = 'format_file_path' [ <bulk_options> ]
| SINGLE_BLOB | SINGLE_CLOB | SINGLE_NCLOB }
} )
<bulk_options> ::=
[ , CODEPAGE = { 'ACP' | 'OEM' | 'RAW' | 'code_page' } ]
[ , ERRORFILE = 'file_name' ]
[ , FIRSTROW = first_row ]
[ , LASTROW = last_row ]
[ , MAXERRORS = maximum_errors ]
[ , ROWS_PER_BATCH = rows_per_batch ]
[ , ORDER ( { column [ ASC | DESC ] } [ ,...n ] ) [ UNIQUE ]
On every page of Microsoft Docs (previously MSDN) that refers to SQL Server (even about OPENROWSET) there is a link called Transact-SQL Syntax Conventions (@Ghost post it in a comment)
That link will guide you to the page with explanation of SQL Syntax Conventions that you seek.
I think the easiest way to understand this syntax is visual Railroad Diagram
.
How to use it:
''
)Image generated using: http://bottlecaps.de/rr/ui
You can also search for Railroad Diagrams
for SQL Server
.
SQL Server CREATE TABLE syntax diagrams
Most important syntax:
- Optional items are enclosed in square brackets
- Groups of expressions are enclosed in curly braces
- A '|' is a binary operator meaning 'or'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With