I have a passion for meta queries, which I mean queries that answer questions about data, not answers to data.
Before I get a lot of legitimate criticism, I understand that the meta-query approach is not ideal, as eloquently described here for example. However, I believe that they have their own place. (So ββmuch so that I created a WinForms user control that supports parameterized meta queries for SQL Server, Oracle, and MySql, and I detail the design and use of this QueryPicker in a three-part series published on Simple-Talk.com.)
My motivation for using meta queries is:
- When I sit down with a new database and want to understand it, I examine meta-queries. The most common ones are those that allow me to answer questions about fields and tables, for example, "What other tables have this" xyz "field?" or "What tables have identifier columns?" or "What are the keys for this table?"
- I regularly work with several types of databases (SQL Server, Oracle, MySql) and - I practice a great ideal for programming laziness - I do not want to search or remember a secret SQL recipe every time I need it, I want to point and click.
Are other (better?) Ways to get meta-information sure for a particular type of database. SQL Server, in particular, provides SQL Server Management Studio. The Oracle and MySql tools do not seem to provide the same benefit. (I completely agree that I am making this expression with my SQL-Server-oriented view of the universe. :-) Even if they did, they would be different - I want a uniform approach to database types.
So finally the question:
What meta-queries in SQL Server, Oracle or MySql do you find useful?
Pivot Matrix
This first view summarizes my collection so far by the type of database (and, as I said, is heavily weighted in SQL Server).
Query SQL Server Oracle MySql
DB Version yes yes yes
Databases with properties yes yes
Databases with space usage yes
National language support yes
Procedures and functions yes yes
Primary keys yes yes
Primary to foreign keys yes
Session Information / brief yes
Session Information / details yes
Session SET options yes
Users and Roles yes
Currently running statements yes
Constraints yes
Indexes yes
Column info / brief yes yes yes
Column info / details yes yes yes
Object level details yes
Rows and space used yes
Row / column counts yes
Non-empty tables yes yes yes
Show table schema yes yes
Seed / max values ββyes
Database Type Links
I myself developed some of these meta queries, but many of them appeared on community forums. This second view lists the source URLs where necessary.
SQL Server
System category
-----------------
DB Version
Databases with properties http://www.mssqltips.com/tip.asp?tip=1033
Databases with space usage http://www.sqlservercentral.com/Forums/Topic261080-5-1.aspx
Procedures and functions
Primary keys http://databases.aspfaq.com/schema-tutorials/schema-how-do-i-show-all-the-primary-keys-in-a-database.html
Primary to foreign keys http://www.sqlservercentral.com/scripts/Miscellaneous/61481/
Session Information / brief http://www.sqlservercentral.com/blogs/glennberry/archive/2009/12/28/how-to-get-a-count-of-sql-connections-by-ip-address.aspx
Session Information / details http://www.mssqltips.com/tip.asp?tip=1817
Session SET options
Users and Roles http://www.sqlservercentral.com/scripts/users/69379/
Currently running statements http://www.sqlservercentral.com/articles/DMV/64425/
Constraints
Indexes http://www.sqlservercentral.com/scripts/Index+Management/63932/
Column Category
-----------------
Column info / brief
Column info / details
Table category
-----------------
Object level details
Rows and space used http://www.mssqltips.com/tip.asp?tip=1177
Row / column counts
Non-empty tables
DDL Category
-----------------
Show table schema http://www.sqlservercentral.com/scripts/Create+DDL+sql+statements/65863/
Data Category
-----------------
Seed / max values
Oracle
System category
-----------------
DB Version
National language support
Column Category
-----------------
Column info / brief
Column info / details
Table category
-----------------
Non-empty tables
DDL Category
-----------------
Show table schema
Mysql
System category
-----------------
DB Version
Databases
Procedures and functions
Primary keys http://databases.aspfaq.com/schema-tutorials/schema-how-do-i-show-all-the-primary-keys-in-a-database.html
Column Category
-----------------
Column info / brief
Column info / details
DDL Category
-----------------
Show table schema