--query table definitions
use AdventureWorks
DECLARE @TableName VARCHAR(128)
DECLARE @TableSchema VARCHAR(128)
--Identify the table name
SET @TableName ='Department'
--identify the table owner ex. dbo
SET @TableSchema='Humanresource'
SELECT Column_Name, COLUMN_DEFAULT,IS_NULLABLE AS ALLOW_NULL,DATA_TYPE,ISNULL(CHARACTER_MAXIMUM_LENGTH,0)[Max Length],
ISNULL(NUMERIC_PRECISION,0)[Precision],
ISNULL(NUMERIC_SCALE,0)[Scale]
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME=@TableName
AND TABLE_SCHEMA=@TableSchema ORDER BY ORDINAL_POSITION
No comments:
Post a Comment