1
我鏈接到表中的SQL Server從MS Access前端。有一些SQL Server表中的列描述,我想在Access中創建鏈接表時提出。有沒有辦法通過編程獲得列描述?檢索SQL Server鏈接表列說明在MS Access
(我知道如何描述追加到鏈接表,我只是需要幫助在後端的描述得到。)
我鏈接到表中的SQL Server從MS Access前端。有一些SQL Server表中的列描述,我想在Access中創建鏈接表時提出。有沒有辦法通過編程獲得列描述?檢索SQL Server鏈接表列說明在MS Access
(我知道如何描述追加到鏈接表,我只是需要幫助在後端的描述得到。)
試着這麼做:
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
很不錯的。我特別喜歡2005+與早期版本的正確屬性表之間自動切換的條件。 – mwolfe02 2011-02-01 17:09:10