gpt4 book ai didi

sql - 最有用的 SQL 元查询

转载 作者:行者123 更新时间:2023-12-02 21:08:52 25 4
gpt4 key购买 nike

我对元查询充满热情,我的意思是回答关于数据的问题,而不是数据回答问题。

在我得到很多合理的批评之前,我确实意识到元查询的方法并不理想,正如 Eloquent 地描述的那样here例如。尽管如此,我相信他们确实有自己的位置。 (以至于我创建了一个支持 SQL Server、Oracle 和 MySql 参数化元查询的 WinForms 用户控件,并且我在 Simple-Talk.com 上发布的 three-part series 中广泛描述了此 QueryPicker 的设计和使用。 )

我使用元查询的动机:

  1. 当我坐下来研究一个新数据库并想要了解它时,我会使用元查询进行探测。最常见的是那些让我回答有关字段和表的问题,例如“其他哪些表有这个‘xyz’字段?”或“哪些表有标识列?”或“这个表的键是什么?”
  2. 我经常使用多种数据库类型(SQL Server、Oracle、MySql),并且实践伟大的懒惰编程理想,我不想每次需要时都必须查找或记住晦涩难懂的 SQL 配方。我想要指向并点击。

当然还有其他(更好?)方法来获取给定数据库类型的元信息。。 SQL Server 特别提供了 SQL Server Management Studio。 Oracle 和 MySql 工具似乎没有提供相同的用处。 (我坦率地承认,我是用我的 SQL-Server 世界观来做出这一主张的。:-) 即使他们这样做了,它们也会有所不同——我想要一种跨数据库类型的统一方法 em>.

<小时/>

最后,问题是:

您认为哪些 SQL Server、Oracle 或 MySql 元查询有用?

<小时/>

汇总矩阵

第一个 View 按数据库类型总结了我迄今为止的收集(并且,正如我所说,主要针对 SQL Server)。

Query                            SQL Server    Oracle     MySqlDB Version                           yes        yes        yesDatabases with properties            yes                   yesDatabases with space usage           yesNational Language Support                       yesProcedures and functions             yes                   yesPrimary keys                         yes                   yesPrimary to foreign keys              yesSession Information/brief            yesSession Information/details          yesSession SET options                  yesUsers and Roles                      yesCurrently running statements         yesConstraints                          yesIndexes                              yesColumn info/brief                    yes        yes        yesColumn info/details                  yes        yes        yesObject level details                 yesRows and space used                  yesRow/column counts                    yesNon-empty tables                     yes        yes        yesShow table schema                    yes        yesSeed/max values                      yes
<小时/>

按数据库类型划分的引用文献

我自己开发了一些元查询,但许多元查询来自社区论坛。第二个 View 在适当的情况下逐项列出了源 URL。

SQL 服务器

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/detailsTable Category-----------------    Object level details    Rows and space used          http://www.mssqltips.com/tip.asp?tip=1177    Row/column counts    Non-empty tablesDDL Category-----------------    Show table schema            http://www.sqlservercentral.com/scripts/Create+DDL+sql+statements/65863/Data Category-----------------    Seed/max values

甲骨文

System Category-----------------    DB Version    National Language SupportColumn Category-----------------    Column info/brief    Column info/detailsTable Category-----------------    Non-empty tablesDDL 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.htmlColumn Category-----------------    Column info/brief    Column info/detailsDDL Category-----------------    Show table schema

最佳答案

Oracle SQL Developer 有一组包含这些类别的内置报告。我扩展了其中一个类别。

About Your Database
All Objects
Application Express
ASH and AWR
Database Administration
All Tables
Cursors
Database Parameters
Locks
Memory
Sessions
Storage
Top SQL
Users
Waits and Events
Data Dictionary
Jobs
PLSQL
Security
Streams
Table
XML

这些是一些实际的报告名称,

Tables without Indexes
Tables without Primary Keys
Tables with Unindexed Foreign Keys
Largest Average Row Length
Most Rows
Unusable Indexes

还有更多可用报告。

关于sql - 最有用的 SQL 元查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2321704/

25 4 0