-- =============================================
-- Author: yenange
-- Create date: 2023-06-07
-- Description: 获取某个表某个字段的默认值
-- =============================================
CREATE OR ALTER FUNCTION dbo.Fun_Util_GetDefaultValue
(
@tableName NVARCHAR(128),
@columnName NVARCHAR(128)
)
RETURNS NVARCHAR(1024)
AS
BEGIN
DECLARE @r NVARCHAR(1024)=''
SELECT @r=REPLACE(REPLACE(definition,'(',''),')','')
FROM sys.default_constraints
WHERE parent_object_id = OBJECT_ID(@tableName) AND
parent_column_id = COLUMNPROPERTY(OBJECT_ID(@tableName), @columnName, 'ColumnId');
RETURN @r;
END
GO
SqlServer: 获取某个表某个字段的默认值
最新推荐文章于 2024-08-07 10:59:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)