<small id='oYjwp'></small><noframes id='oYjwp'>

      <bdo id='oYjwp'></bdo><ul id='oYjwp'></ul>

    <legend id='oYjwp'><style id='oYjwp'><dir id='oYjwp'><q id='oYjwp'></q></dir></style></legend>
  1. <tfoot id='oYjwp'></tfoot>

      <i id='oYjwp'><tr id='oYjwp'><dt id='oYjwp'><q id='oYjwp'><span id='oYjwp'><b id='oYjwp'><form id='oYjwp'><ins id='oYjwp'></ins><ul id='oYjwp'></ul><sub id='oYjwp'></sub></form><legend id='oYjwp'></legend><bdo id='oYjwp'><pre id='oYjwp'><center id='oYjwp'></center></pre></bdo></b><th id='oYjwp'></th></span></q></dt></tr></i><div id='oYjwp'><tfoot id='oYjwp'></tfoot><dl id='oYjwp'><fieldset id='oYjwp'></fieldset></dl></div>

      SQL Server 2008 - 获取表约束

      SQL Server 2008- Get table constraints(SQL Server 2008 - 获取表约束)
      <legend id='wb0eA'><style id='wb0eA'><dir id='wb0eA'><q id='wb0eA'></q></dir></style></legend>

    1. <tfoot id='wb0eA'></tfoot>
        <bdo id='wb0eA'></bdo><ul id='wb0eA'></ul>

          <small id='wb0eA'></small><noframes id='wb0eA'>

            <tbody id='wb0eA'></tbody>

                <i id='wb0eA'><tr id='wb0eA'><dt id='wb0eA'><q id='wb0eA'><span id='wb0eA'><b id='wb0eA'><form id='wb0eA'><ins id='wb0eA'></ins><ul id='wb0eA'></ul><sub id='wb0eA'></sub></form><legend id='wb0eA'></legend><bdo id='wb0eA'><pre id='wb0eA'><center id='wb0eA'></center></pre></bdo></b><th id='wb0eA'></th></span></q></dt></tr></i><div id='wb0eA'><tfoot id='wb0eA'></tfoot><dl id='wb0eA'><fieldset id='wb0eA'></fieldset></dl></div>
                本文介绍了SQL Server 2008 - 获取表约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                你能帮我构建一个查询来检索所有表中的约束、每个表中的约束计数,并为没有任何约束的表显示 NULL.

                Could you help me frame a query that retrieves the constraints in all the tables, the count of constraints in each table, and also display NULL for tables that do NOT have any constraints.

                这是我目前所拥有的:

                Select  SysObjects.[Name] As [Constraint Name] ,
                        Tab.[Name] as [Table Name],
                        Col.[Name] As [Column Name]
                From SysObjects Inner Join 
                (Select [Name],[ID] From SysObjects) As Tab
                On Tab.[ID] = Sysobjects.[Parent_Obj] 
                Inner Join sysconstraints On sysconstraints.Constid = Sysobjects.[ID] 
                Inner Join SysColumns Col On Col.[ColID] = sysconstraints.[ColID] And Col.[ID] = Tab.[ID]
                order by [Tab].[Name] 
                

                推荐答案

                您应该使用当前的 sys 目录视图(如果您使用的是 SQL Server 2005 或更高版本- sysobjects 视图已弃用,应避免使用)- 查看 关于目录视图的大量 MSDN SQL Server 在线文档.

                You should use the current sys catalog views (if you're on SQL Server 2005 or newer - the sysobjects views are deprecated and should be avoided) - check out the extensive MSDN SQL Server Books Online documentation on catalog views here.

                您可能会对很多视图感兴趣:

                There are quite a few views you might be interested in:

                • sys.default_constraints 用于列的默认约束
                • sys.check_constraints 用于检查列的约束
                • sys.key_constraints 用于键约束(例如主键)
                • sys.foreign_keys 用于外键关系
                • sys.default_constraints for default constraints on columns
                • sys.check_constraints for check constraints on columns
                • sys.key_constraints for key constraints (e.g. primary keys)
                • sys.foreign_keys for foreign key relations

                还有更多 - 看看吧!

                您可以查询并加入这些视图以获取所需的信息 - 例如这将列出表、列和在它们上定义的所有默认约束:

                You can query and join those views to get the info needed - e.g. this will list the tables, columns and all default constraints defined on them:

                SELECT 
                    TableName = t.Name,
                    ColumnName = c.Name,
                    dc.Name,
                    dc.definition
                FROM sys.tables t
                INNER JOIN sys.default_constraints dc ON t.object_id = dc.parent_object_id
                INNER JOIN sys.columns c ON dc.parent_object_id = c.object_id AND c.column_id = dc.parent_column_id
                ORDER BY t.Name
                

                这篇关于SQL Server 2008 - 获取表约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                SQL query to group by day(按天分组的 SQL 查询)
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  <tfoot id='LSKwi'></tfoot>
                    <tbody id='LSKwi'></tbody>

                  <small id='LSKwi'></small><noframes id='LSKwi'>

                    • <bdo id='LSKwi'></bdo><ul id='LSKwi'></ul>
                    • <i id='LSKwi'><tr id='LSKwi'><dt id='LSKwi'><q id='LSKwi'><span id='LSKwi'><b id='LSKwi'><form id='LSKwi'><ins id='LSKwi'></ins><ul id='LSKwi'></ul><sub id='LSKwi'></sub></form><legend id='LSKwi'></legend><bdo id='LSKwi'><pre id='LSKwi'><center id='LSKwi'></center></pre></bdo></b><th id='LSKwi'></th></span></q></dt></tr></i><div id='LSKwi'><tfoot id='LSKwi'></tfoot><dl id='LSKwi'><fieldset id='LSKwi'></fieldset></dl></div>
                        <legend id='LSKwi'><style id='LSKwi'><dir id='LSKwi'><q id='LSKwi'></q></dir></style></legend>