从 MS Access 中的 SQL Server 链接表检索列描述

发布于 2024-10-15 11:03:56 字数 143 浏览 0 评论 0原文

我从 MS Access 前端链接到 SQL Server 中的表。当我在 Access 中创建链接表时,我想提出 SQL Server 中某些表的列描述。有没有办法以编程方式获取列描述?

(我知道如何将描述附加到链接表中,我只需要帮助获取后端的描述。)

I am linking to tables in SQL Server from an MS Access front-end. There are column descriptions for some of the tables in SQL Server that I would like to bring forward when I create the linked tables in Access. Is there a way to get at the column descriptions programmatically?

(I know how to append the description to the linked tables, I just need help getting at the descriptions in the back end.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Oo萌小芽oO 2024-10-22 11:03:56

尝试类似的方法:

DECLARE @TableName varchar(100)
SELECT @TableName = 'yourtablename'


-- This will determine if we're using version 9 (2005) of SQL Server, and execute code accordingly

IF CAST(REPLACE(SUBSTRING(CAST(SERVERPROPERTY('productversion') as varchar),1,2), '.','') as int) >= 9
BEGIN
      -- This is a SQL 2005 machine
      SELECT  
            [Table Name] = OBJECT_NAME(c.object_id), 
            [Column Name] = c.name, 
            [Description] = ex.value  
      FROM  
            sys.columns c  
      LEFT OUTER JOIN  
            sys.extended_properties ex  
      ON  
            ex.major_id = c.object_id 
            AND ex.minor_id = c.column_id  
            AND ex.name = 'MS_Description'  
      WHERE  
            OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0  
            AND OBJECT_NAME(c.object_id) = @TableName
      ORDER  
            BY OBJECT_NAME(c.object_id), c.column_id
END
ELSE
BEGIN
      -- assume this is a SQL 2000
      SELECT 
            [Table Name] = i_s.TABLE_NAME, 
            [Column Name] = i_s.COLUMN_NAME, 
            [Description] = s.value 
      FROM 
            INFORMATION_SCHEMA.COLUMNS i_s 
      LEFT OUTER JOIN 
            sysproperties s 
      ON 
            s.id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) 
            AND s.smallid = i_s.ORDINAL_POSITION 
            AND s.name = 'MS_Description' 
      WHERE 
            OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0 
            AND i_s.TABLE_NAME = @TableName
      ORDER BY
            i_s.TABLE_NAME, i_s.ORDINAL_POSITION 
END

Try something like:

DECLARE @TableName varchar(100)
SELECT @TableName = 'yourtablename'


-- This will determine if we're using version 9 (2005) of SQL Server, and execute code accordingly

IF CAST(REPLACE(SUBSTRING(CAST(SERVERPROPERTY('productversion') as varchar),1,2), '.','') as int) >= 9
BEGIN
      -- This is a SQL 2005 machine
      SELECT  
            [Table Name] = OBJECT_NAME(c.object_id), 
            [Column Name] = c.name, 
            [Description] = ex.value  
      FROM  
            sys.columns c  
      LEFT OUTER JOIN  
            sys.extended_properties ex  
      ON  
            ex.major_id = c.object_id 
            AND ex.minor_id = c.column_id  
            AND ex.name = 'MS_Description'  
      WHERE  
            OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0  
            AND OBJECT_NAME(c.object_id) = @TableName
      ORDER  
            BY OBJECT_NAME(c.object_id), c.column_id
END
ELSE
BEGIN
      -- assume this is a SQL 2000
      SELECT 
            [Table Name] = i_s.TABLE_NAME, 
            [Column Name] = i_s.COLUMN_NAME, 
            [Description] = s.value 
      FROM 
            INFORMATION_SCHEMA.COLUMNS i_s 
      LEFT OUTER JOIN 
            sysproperties s 
      ON 
            s.id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) 
            AND s.smallid = i_s.ORDINAL_POSITION 
            AND s.name = 'MS_Description' 
      WHERE 
            OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0 
            AND i_s.TABLE_NAME = @TableName
      ORDER BY
            i_s.TABLE_NAME, i_s.ORDINAL_POSITION 
END
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文