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