Successfully reported this slideshow.
Get a Lever and Pick Any Turtle:Lifting with Metadata<br />Cade Roux<br />cade@roux.org<br />
Give me the place to stand, and I shall move the earth.<br />
Start Simple<br />
Scalethe Technique<br />
Use<br />Basic<br />Concepts<br />
Expand to Systems<br />
Mixing Metaphors – We’re Going Down a Rabbit Hole<br />Pam: And then outta that cake pops another stripper holding a small...
Avoid Injury<br />
Metadata has always been there<br />Codd Rule #0: The RDBMS must use the relational facilities to manage the database<br />
Metadata has always been there<br />Codd Rule #4: There must be an active online catalog based on the relational model<br />
DBMeta<br />DBHealth<br />Demo<br />
Tables<br />Views<br />SPs<br />
SQL Server Basic Metadata Services<br />INFORMATION_SCHEMA contains tables and views (ANSI 92, kind of generic RDBMS model...
SQL Server Extended Properties<br />You could make tables of additional information about database objects<br />DON’T<br /...
DBMeta.Properties<br />Layer this view on top of sys.extended_propertiesto:<br />Make it easier to use<br />Give a standar...
DBMeta.AddXP, UpdateXP, DropXP<br />Easier to use than sp_addextendedproperty, sp_updateextendedproperty, sp_dropextendedp...
DBMeta<br />With some simple tools we now have an easier way of dealing with the metadata in the extended properties<br />...
DBHealth<br />Some questions about the health of the database system will be very standard<br />By health, I mean outside ...
Demo Data<br />Let’s create some data structures in our Demo schema – some tables and indexes<br />
Let’s Make Up Some DBA Rules<br />Arbitrary, but useful and chosen for variety<br />Rule #1: All tables should be identifi...
Rule #0<br />We simply make a view DBHealth.MonitoredSchemas<br />We’ll need to remember to use this view<br />You could m...
Rule #1<br />Look for tables without extended property ‘SUBSYSTEM’<br />
Rule #2<br />Look for unique indexes where any of the columns in the index are NULLable.<br />
Rule #3<br />Find all varchar/nvarchar columns with length <= 2<br />
What about exclusions?<br />Let’s tag things for exclusion with extended properties!<br />
Now we have a bunch of rules<br />How do we organize them?<br />Could we put them in individual views or procedures to mak...
Ideas For Rules<br />All procs in DBHealth should have HEALTH_CHECK_PROC and HEALTH_CHECK_SET properties<br />Show me any ...
Let’s use this from a client<br />Health Monitoring<br />.NET<br />Code Generation<br />T-SQL<br />T4<br />
Contact<br />Email: cade@roux.org<br />Twitter: @caderoux<br />Web: http://www.caderoux.com<br />SpeakerRate: http://speak...
Upcoming SlideShare
Loading in …5
×

Get a Lever and Pick Any Turtle - Lifting with Metadata

4,678 views

Published on

Presentation about SQL Server metadata features, using them to document and monitor the health of databases and to generate code for more maintainable systems.

Published in: Technology
  • Be the first to comment

Get a Lever and Pick Any Turtle - Lifting with Metadata

  1. 1. Get a Lever and Pick Any Turtle:Lifting with Metadata<br />Cade Roux<br />cade@roux.org<br />
  2. 2. Give me the place to stand, and I shall move the earth.<br />
  3. 3. Start Simple<br />
  4. 4. Scalethe Technique<br />
  5. 5. Use<br />Basic<br />Concepts<br />
  6. 6. Expand to Systems<br />
  7. 7. Mixing Metaphors – We’re Going Down a Rabbit Hole<br />Pam: And then outta that cake pops another stripper holding a smaller cake and then an even smaller stripper pops outta that one.<br />Michael: What is that smaller stripper holding?<br />Pam: A cupcake! It's cupcakes and strippers all the way down.<br />
  8. 8. Avoid Injury<br />
  9. 9. Metadata has always been there<br />Codd Rule #0: The RDBMS must use the relational facilities to manage the database<br />
  10. 10. Metadata has always been there<br />Codd Rule #4: There must be an active online catalog based on the relational model<br />
  11. 11. DBMeta<br />DBHealth<br />Demo<br />
  12. 12. Tables<br />Views<br />SPs<br />
  13. 13. SQL Server Basic Metadata Services<br />INFORMATION_SCHEMA contains tables and views (ANSI 92, kind of generic RDBMS model, doesn’t expose a lot of implementation details)<br />sys schema contains tables and views (more proprietary, particularly non-portable things like indexing features)<br />
  14. 14. SQL Server Extended Properties<br />You could make tables of additional information about database objects<br />DON’T<br />Built-in extended properties work great for this!<br />MS_Description: Microsoft’s standard “description” property<br />sp_addextendedproperty, sp_updateextendedproperty, sp_dropextendedproperty<br />fn_listextendedproperty<br />sys.extended_properties<br />I’ll improve this in the DBMeta schema<br />
  15. 15. DBMeta.Properties<br />Layer this view on top of sys.extended_propertiesto:<br />Make it easier to use<br />Give a standard naming convention<br />Easier than CROSS APPLY fn_listextendedproperty<br />
  16. 16. DBMeta.AddXP, UpdateXP, DropXP<br />Easier to use than sp_addextendedproperty, sp_updateextendedproperty, sp_dropextendedproperty<br />The builtinprocs have some awkward hierarchy aspects: e.g. a column or trigger is defined at level 2 where the table is level 1<br />
  17. 17. DBMeta<br />With some simple tools we now have an easier way of dealing with the metadata in the extended properties<br />This can be expanded at will to join regular base metadata information, PIVOT with the property information and combine them in interesting ways<br />For instance, say your question was “I want to see NULLability (base metadata) of all money (base metadata) columns in tables in the Accounts subsystem (extended property) which have not been marked as reviewed. (extended property)” You can do that.<br />
  18. 18. DBHealth<br />Some questions about the health of the database system will be very standard<br />By health, I mean outside of integrity you can realistically enforce with constraints and beyond what you might use DDL triggers for<br />Can we use the metadata to do something generally useful?<br />Can we organize the health system using metadata so that it is self-maintaining as much a possible?<br />
  19. 19. Demo Data<br />Let’s create some data structures in our Demo schema – some tables and indexes<br />
  20. 20. Let’s Make Up Some DBA Rules<br />Arbitrary, but useful and chosen for variety<br />Rule #1: All tables should be identified with a SUBSYSTEM (Organizational Rule)<br />Rule #2: No unique indexes with columns which allow NULLs (Indexing Rule)<br />Rule #3: No varchar(N) columns where N <= 2 (Table Design Rule)<br />Rule #0: We only want to enforce these on schemas under management<br />
  21. 21. Rule #0<br />We simply make a view DBHealth.MonitoredSchemas<br />We’ll need to remember to use this view<br />You could make a whole layer of views which filter through this, of course<br />
  22. 22. Rule #1<br />Look for tables without extended property ‘SUBSYSTEM’<br />
  23. 23. Rule #2<br />Look for unique indexes where any of the columns in the index are NULLable.<br />
  24. 24. Rule #3<br />Find all varchar/nvarchar columns with length <= 2<br />
  25. 25. What about exclusions?<br />Let’s tag things for exclusion with extended properties!<br />
  26. 26. Now we have a bunch of rules<br />How do we organize them?<br />Could we put them in individual views or procedures to make them easy to use?<br />Then make a master procedure which runs them all.<br />But we’d need to make a list of all the procedures<br />But what did we say?<br />Let’s use the metadata to tag the procedures!<br />We’ll mark the procedures<br />We’ll categorize the procedures<br />We’ll be able to look for all the marked procedures and run them in an automated fashion – no new tables, limited maintenance!<br />
  27. 27. Ideas For Rules<br />All procs in DBHealth should have HEALTH_CHECK_PROC and HEALTH_CHECK_SET properties<br />Show me any unindexed tables (heap tables with no non-clustered indexes)<br />Show me any items tagged with a ‘TODO’ extended property<br />Show me all columns in the database which aren’t actually used (yes, you can do this!)<br />
  28. 28. Let’s use this from a client<br />Health Monitoring<br />.NET<br />Code Generation<br />T-SQL<br />T4<br />
  29. 29. Contact<br />Email: cade@roux.org<br />Twitter: @caderoux<br />Web: http://www.caderoux.com<br />SpeakerRate: http://speakerrate.com/caderoux<br />

×