获取默认约束信息

Getting Default Constraints Information(获取默认约束信息)
本文介绍了获取默认约束信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取给定表的默认约束信息.我是这样写的:

I am trying to get the Default Constraints information for a given table. I wrote something like this:

SELECT  c.name ,
        col.name
FROM    Rem.sys.default_constraints c
        INNER JOIN Rem.sys.columns col ON col.default_object_id = c.object_id
        INNER JOIN Rem.sys.objects o ON o.object_id = c.parent_object_id
        INNER JOIN Rem.sys.schemas s ON s.schema_id = o.schema_id       
WHERE   s.name = 'dbo'
        AND o.name = 'Desk_Hist'

但它不会返回我的默认值.所以我尝试了不同的方式,查询是:

But it doesn't return me the default value. So I tried a different way and the query is:

SELECT *
                FROM    Rem.information_schema.columns columns
                WHERE   columns.table_catalog = 'Rem'
                        AND columns.table_schema = 'dbo'
                        AND columns.table_name = 'Desk_Hist'
                        AND COLUMN_DEFAULT IS NOT NULL  

但它什么也没给我返回.

But it returns me nothing.

有人可以帮我吗?

推荐答案

默认值在 'definition' 列中,尝试在没有 where 的情况下运行查询:

Default value is in column 'definition', try to run query without where:

SELECT  c.name , 
        col.name, 
        c.definition
FROM    Rem.sys.default_constraints c 
        INNER JOIN Rem.sys.columns col ON col.default_object_id = c.object_id 
        INNER JOIN Rem.sys.objects o ON o.object_id = c.parent_object_id 
        INNER JOIN Rem.sys.schemas s ON s.schema_id = o.schema_id 

这篇关于获取默认约束信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)