Getting column description and Update descriptions in SQL Server
We are working on code generation and update thought it would be neat to pull
information from description The following query did that trick.
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 sys.extended_properties s
ON s.major_id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) AND s.minor_id = 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 = 'Emp'
ORDER BY i_s.TABLE_NAME, i_s.ORDINAL_POSITION
UPDATE DESCRIPTION:
EXEC sp_updateextendedproperty
@name = N'MS_Description'
,@value = 'Emp Number must be Unique'
,@level0type = N'Schema', @level0name = dbo
,@level1type = N'Table', @level1name = emp
,@level2type = N'Column', @level2name = empno;
ADD NEW COLUMN DESCRIPTION:
EXEC sp_addextendedproperty
@name = N'MS_Description'
,@value = 'Employee Name'
,@level0type = N'Schema', @level0name = dbo
,@level1type = N'Table', @level1name = emp
,@level2type = N'Column', @level2name = ename;
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 sys.extended_properties s
ON s.major_id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) AND s.minor_id = 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 = 'Emp'
ORDER BY i_s.TABLE_NAME, i_s.ORDINAL_POSITION
UPDATE DESCRIPTION:
EXEC sp_updateextendedproperty
@name = N'MS_Description'
,@value = 'Emp Number must be Unique'
,@level0type = N'Schema', @level0name = dbo
,@level1type = N'Table', @level1name = emp
,@level2type = N'Column', @level2name = empno;
ADD NEW COLUMN DESCRIPTION:
EXEC sp_addextendedproperty
@name = N'MS_Description'
,@value = 'Employee Name'
,@level0type = N'Schema', @level0name = dbo
,@level1type = N'Table', @level1name = emp
,@level2type = N'Column', @level2name = ename;
Subscribe to:
Post Comments (Atom)
1 comments:
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
rpa training in electronic city | rpa training in chennai
rpa online training | selenium training in training
Post a Comment