SQL Server:使用查询找出列的默认值 [英] SQL Server: Find out default value of a column with a query

查看:188
本文介绍了SQL Server:使用查询找出列的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用SQL查询找出表中列的默认值?

How can I find out the default value of a column in a table using a SQL query?

通过使用此存储过程:

sp_columns @tablename 

I获取有关特定表的列的一些信息,但缺少列的默认值,如何获取?

I get some information on the columns of a particular table but the default value of the columns is missing, How can I get it?

推荐答案

您可以在下面找到存储的定义(请记住要调整列和表名以查找与您的环境有关的定义!)

You can find the stored definition with the below (remember to adjust the column and table name to find to be ones relevant to your environment!)

SELECT object_definition(default_object_id) AS definition
FROM   sys.columns
WHERE  name      ='colname'
AND    object_id = object_id('dbo.tablename')

这篇关于SQL Server:使用查询找出列的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆