2017-04-04 114 views
0

SP_HELP過程生成多個數據子集,我只想從中獲取列信息。有沒有辦法使用sp_help編寫查詢來提取這些信息。SQL Server sp_help只提取列信息

我需要這樣做來建立一個元數據庫並且每週保持它。任何幫助表示讚賞。

謝謝, RV。

+0

你只是在尋找列和他們相關的元數據的列表? –

+0

是的。我需要的主要信息是column_name,數據類型,長度和可空性。謝謝。 – rvphx

回答

2

你想要的信息可以發現:

select * from sys.columns 

但是,它可能很難只使用該表進行導航。我喜歡爲此查詢模式,表和列視圖。

select 
    schemas.name as [schema] 
    ,tables.name as [table] 
    ,columns.* 
from sys.schemas 
join sys.tables on 
    schemas.schema_id = tables.schema_id 
join sys.columns on 
    tables.object_id = columns.object_id 

您可以瞭解更多信息here

0
SELECT * 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = 'SchemaName' 
     AND TABLE_NAME = 'TableName' 

這應該有效。