Coolthing Of Theday

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 8 October 2013

This is a railroading you'll actually look forward too... Generating SQL Railroad Diagrams

Posted on 18:18 by Unknown

simple talk - How to get SQL Railroad Diagrams from MSDN BNF syntax notation.

On SQL Server Books-On-Line, in the Transact-SQL Reference (database Engine), every SQL Statement has its syntax represented in ‘Backus–Naur Form’ notation (BNF) syntax. For a programmer in a hurry, this should be ideal because It is the only quick way to understand and appreciate all the permutations of the syntax. It is a great feature once you get your eye in. It isn’t the only way to get the information; You can, of course, reverse-engineer an understanding of the syntax from the examples, but your understanding won’t be complete, and you’ll have wasted time doing it. BNF is a good start in representing the syntax: Oracle and SQLite go one step further, and have proper railroad diagrams for their syntax, which is a far more accessible way of doing it.

There are three problems with the BNF on MSDN. Firstly, it is isn’t a standard version of BNF, but an ancient fork from EBNF, inherited from Sybase. Secondly, it is excruciatingly difficult to understand, and thirdly it has a number of syntactic and semantic errors. The page describing DML triggers, for example, currently has the absurd BNF error that makes it state that all statements in the body of the trigger must be separated by commas. There are a few other detail problems too. Here is the offending syntax for a DML trigger, pasted from MSDN.

image

...

I’ve been trying to create railroad diagrams for all the important SQL Server SQL statements, as good as you’d find for Oracle, and have so far published the CREATE TABLE and ALTER TABLE railroad diagrams based on the BNF. Although I’ve been aware of them, I’ve never realised until recently how many errors there are. Then, Colin Daley created a translator for the SQL Server dialect of BNF which outputs standard EBNF notation used by the W3C. The example MSDN BNF for the trigger would be rendered as …

...

Colin’s intention was to allow anyone to paste SQL Server’s BNF notation into his website-based parser, and from this generate classic railroad diagrams via Gunther Rademacher's Railroad Diagram Generator.  Colin's application does this for you: you're not aware that you are moving to a different site.  Because Colin's 'translator' it is a parser, it will pick up syntax errors. Once you’ve fixed the syntax errors, you will get the syntax in the form of a human-readable railroad diagram and, in this form, the semantic mistakes become flamingly obvious.

Gunter’s Railroad Diagram Generator is brilliant. To be able, after correcting the MSDN dialect of BNF, to generate a standard EBNF, and from thence to create railroad diagrams for SQL Server’s syntax that are as good as Oracle’s, is a great boon, and many thanks to Colin for the idea. Here is the result of the W3C EBNF from Colin’s application then being run through the Railroad diagram generator.

image

Now that’s much better, you’ll agree. This is pretty easy to understand, and at this point any error is immediately obvious.

This should be seriously useful, and it is to me. However there is that snag. The BNF is generally incorrect, and you can’t expect the average visitor to mess about with it.

The answer is, of course, to correct the BNF on MSDN and maybe even add railroad diagrams for the syntax. Stop giggling! I agree it won’t happen. In the meantime, we need to collaboratively store and publish these corrected syntaxes ourselves as we do them. How? GitHub? SQL Server Central?  Simple-Talk? What should those of us who use the system do with our corrected EBNF so that anyone can use them without hassle?

Grammar Translator

If you are familiar with the Grammar Translator, go ahead and create railroad diagrams from the Transact-SQL Reference. Otherwise, please see the FAQ. In particular, be sure to try the tutorial.

image

image

Welcome to Railroad Diagram Generator!

This is a tool for creating syntax diagrams, also known as railroad diagrams, from context-free grammars specified in EBNF. Syntax diagrams have been used for decades now, so the concept is well-known, and some tools for diagram generation are in existence. The features of this one are

  • usage of the W3C's EBNF notation,
  • web-scraping of grammars from W3C specifications,
  • online editing of grammars,
  • diagram presentation in SVG,
  • and it was completely written in web languages (XQuery, XHTML, CSS, JavaScript).

image

There's nothing like a diagram to help grok something (and the MSDN BNF SQL stuff really makes my brain hurt...)

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in DBA, SQLServer | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Mr. 7,000! This is my 7,000th post...
    Before this post; After; 20 visits between taking these snaps? Oh wait, that's probably me searching for past related posts....
  • "Windows Server Essentials Media Pack" (DNLA Stream, HTML5 and Dashboard Media stuff)
    Microsoft Downloads - Windows Server Essentials Media Pack This pack enables the media streaming functionality for Windows Server 2012...
  • Rad Gate Post... Get your Red Gate Post here...
    simple talk - Melanie Townsend - Get a copy of the Red Gate Post We recently put together a newspaper of some of the best articles fr...
  • Windows Management Framework 4.0 (PowerShell 4, PowerShell ISE, Management OData, WMI, etc.) now available
    Keith Hill's Blog - PowerShell 4.0 Now Available You can get PowerShell 4.0 for down level operating systems now via the WMF 4.0 d...
  • Viasfora - Your new favorite Visual Studio Text/*ML Editing Extension?
    Winterdom - Introducing Viasfora A couple of days ago, I unveiled Viasfora , my latest attempt at building a decently packaged extensi...
  • "Windows Server [2012 R2]: The Best Infrastructure to Run Linux Workloads"
    In the Cloud - What’s New in 2012 R2: Enabling Open Source Software Part 4 of a 9-part series . ... There are a lot of great s...
  • [Hardware Review] Life with Haswell... Haswell/Harris Beach Intel SDS Ultrabook Review - Part 2
    "So Greg, how's life with Haswell been?" "Pretty Sweet! (Mostly)" I've been given an opportunity to review t...
  • Fuzzy Lookup Add-In for Excel (Insert lame "Fuzzy, wuzzy was an Excel..." snip here)
    Microsoft Downloads - Fuzzy Lookup Add-In for Excel The Fuzzy Lookup Add-In for Excel performs fuzzy matching of textual data in Exce...
  • Caliburn.Micro v1.5.0 released (CM gets Tasks, Async/Await and Share/Setting for RT... and bug fixes of course)
    Caliburn.Micro - Caliburn.Micro v1.5.0 "Release Notes This release fixes many bugs. It also adds support for Task and async/a...
  • Just about everything you ever wanted to know about SQL Server Date and Time Data Types...
    CodeProject - Date and Time Data Types and Functions - SQL Server (2000, 2005, 2008, 2008 R2, 2012) Introduction It would be bette...

Categories

  • .Net
  • 3DPrinting
  • AFeedYouShouldRead
  • Agile
  • ALM
  • Amazon
  • Amiga
  • Analytics
  • Android
  • ASP.NET
  • Azure
  • BigData
  • bing
  • Blogging
  • Book
  • BookReview
  • BUILD
  • C
  • C#
  • C++
  • Career
  • Cat
  • cheatsheet
  • ClickOnce
  • Cloud
  • ComputerHardware
  • css
  • Data
  • DBA
  • DependencyInjection
  • Deployment
  • Design
  • Development
  • devops
  • DVCS
  • ebook
  • EDD
  • Education
  • EnterpriseLibrary
  • EntityFramework
  • Exchange
  • Expression
  • gadget
  • Game
  • GIT
  • Google
  • Government
  • Hadoop
  • hardware
  • HardwareReview
  • HaswellReview
  • HTML5
  • Humor
  • IE
  • IEExtension
  • IfAllElseFails
  • IIS
  • ILMerge
  • Image
  • Infographic
  • interview
  • InversionOfControl
  • Java
  • Javascript
  • Kinect
  • LightSwitch
  • LINQ
  • Linux
  • LosAngeles
  • Lucene
  • Lync
  • MEF
  • Metro
  • MicrosoftOffice
  • MicrosoftOutlook
  • Mono
  • MVC
  • MVVM
  • NetMon
  • NLP
  • NoSQL
  • NuGet
  • OData
  • OneNote
  • OpenXML
  • Paint.Net
  • Personal
  • Photosynth
  • Physics
  • portable
  • Poster
  • PowerShell
  • Preparedness
  • Presentation
  • Prism
  • PrivateCloud
  • RegEx
  • RemoteDesktop
  • Reporting
  • RIAServices
  • Science
  • ScienceFiction
  • Scratch
  • Scrum
  • ServiceBus
  • SharePoint
  • Silverlight
  • SimiValley
  • SPA
  • Space
  • SQLServer
  • Storyboard
  • Surface
  • SVG
  • SystemAdministration
  • T4
  • TeamBuild
  • TeamFoundationServer
  • TechEd
  • Training
  • TypeScript
  • UnitTesting
  • UnityApplicationBlock
  • Utility
  • Veteran
  • VirtualMachine
  • Visio
  • VisualBasic
  • VisualStudio
  • WCF
  • Web X.X
  • Webcast
  • WebFeed
  • WebMatrix
  • Windows
  • Windows7
  • Windows8
  • Windows8.1
  • WindowsHomeServer
  • WindowsLiveWriter
  • WindowsPhone
  • WindowsServer
  • WinRT
  • WiX
  • WMI
  • WOPI
  • WPF
  • XAML
  • XBox360
  • XboxOne
  • zombie

Blog Archive

  • ▼  2013 (500)
    • ►  December (12)
    • ►  November (61)
    • ▼  October (65)
      • WindowSMART (The HD/SSD health monitoring, reporti...
      • 11 for 12... 11 Free SQL Server 2012 Microsoft Vir...
      • TechBooks, your Windows 8.1 window to discovering,...
      • "Halloween Costumes for Programmers" Comic
      • “Ship it, Maybe” - Yammer's software shipping parody
      • Mr. 7,000! This is my 7,000th post...
      • Welcome OctoGit... I mean, Octokit.Net for GitHub
      • Mastering MDS with the Master Data Services Operat...
      • Windows Azure Guidance - Cloud Design Patterns Alp...
      • "We're from the Government and we're to help with ...
      • Zombie Post of the Day #2: Zombie Combat Battalion...
      • Zombie Post of the Day #1: "Cloudy with a chance o...
      • Hotfix released to remove 'SecureBoot isn't config...
      • Clide, your guide to Visual Studio Extensibility s...
      • Toward Metadata Mastery with the Windows API Code ...
      • "Theory and Applications for Advanced Text Mining"...
      • Seven for SQL... Seven Free eBooks from Pinal Dave...
      • Surface RT Battery draining faster than you're use...
      • Internet Archive's Historical Software Archive = R...
      • Jesse's got your number (of Insanely Essential Pro...
      • Windows Management Framework 4.0 (PowerShell 4, Po...
      • Wriju's TFS 2013 Book and Video Link Round-up
      • XPlatformCloudKit - Your Cross Windows Phone, Wind...
      • Jason's Spa (err... I mean, Jason Haley's new SPA,...
      • Doughnuts! (Well, Infragistics XAML Doughnut Chart...
      • Doughnuts! (Well, Infragistics XAML Doughnut Chart...
      • Only for the cool cats (SQL Cat's are cool be defi...
      • Free eBook of the Day: "45 Database Performance Ti...
      • Page File = RAM x 1.5? Not so fast if you're x64...
      • AsmSpy [Assembly Spy] (Think "commandDepends for ...
      • "Introducing Windows 8.1 for IT Professionals: Tec...
      • patterns & practices: Data Access Guidance code dr...
      • "Windows Server Essentials Media Pack" (DNLA Strea...
      • You can only turn "SecureBoot isn't configured cor...
      • sp_AskBrent - Your new, "OMG, my SQL Server is soo...
      • Shining the light on 30 Code Samples, 9 Technologi...
      • bing up your app with the new Bing Speech Recognit...
      • Magic Method to Move from Windows 8.1 Preview to W...
      • Visual Studio 2013, Team Foundation Server 2013, ....
      • Windows 8.1 Now Available...(For Everyone)
      • [Hardware Review] It's been a Haswell Summer... Ha...
      • Revisiting Sando - Full Text Index and Source your...
      • IntelliCommand, the key to learning Visual Studio ...
      • PIE! (charts) - Log Parser and the Office Web Comp...
      • Besides tearing your hair out, how you debug why y...
      • Some TweetSharp, Accord.Net and the author's code ...
      • Habitat for Humanity SF/SCV, USO Greater Los Angel...
      • //? = Taking "Google Coding" to the next level? Fl...
      • This is a railroading you'll actually look forward...
      • How do the Microsoft Office Servers Integrate? Her...
      • Making SQL Server a happy kCura Relativity camper ...
      • Grant's TFS Grooming Guide (Think "How to keep you...
      • OpenGov.com, where your Local Government can get n...
      • Comparing Sentiment Analysis REST API's
      • XAML Spy v2 Beta Visual Studio now available... (t...
      • DebugDiag v2 is now out...
      • The Surface surface... Three Surface sites you sho...
      • VMware or Microsoft? 35 posts, six weeks, two prod...
      • No need to say no to NoSql - "Data Access for High...
      • Can you Kinect me now... Using the Kinect for Wind...
      • A Decade+ of Start Pages - Visual Studio Start Pag...
      • [Insert really lame Mime joke here] MimeKit v0.5 (...
      • Lets Get Physical [JavaScript] - PhysicsJS
      • WAMVA - Windows Azure Microsoft Virtual Academy co...
      • This is IT for Azure... "Introducing Windows Azure...
    • ►  September (38)
    • ►  August (47)
    • ►  July (75)
    • ►  June (39)
    • ►  May (40)
    • ►  April (42)
    • ►  March (39)
    • ►  February (42)
Powered by Blogger.

About Me

Unknown
View my complete profile