SELECT NAME as dbName FROM Master..SysDatabases ORDER BY NAME
SELECT NAME as tableName, ID as tableId FROM ${dbName}..SysObjects Where XType='U' ORDER BY NAME
WITH PRIMARYINFO( COLUMNNAME ,ISPRAMARY) AS ( SELECT C.NAME,'true' AS COLUMNNAME FROM SYSINDEXES I JOIN SYSINDEXKEYS K ON I.ID = K.ID AND I.INDID = K.INDID JOIN SYSOBJECTS O ON I.ID = O.ID JOIN SYSCOLUMNS C ON I.ID=C.ID AND K.COLID = C.COLID WHERE O.XTYPE = 'U' AND EXISTS(SELECT 1 FROM SYSOBJECTS WHERE XTYPE = 'PK' AND NAME = I.NAME) AND O.NAME=#{tableName} ) SELECT ( SELECT IS_IDENTITY FROM SYS.ALL_COLUMNS WHERE SYS.ALL_COLUMNS.NAME=SYSCOLUMNS.NAME AND OBJECT_ID = OBJECT_ID(#{tableName}) ) ISIDENTITY,SYSCOLUMNS.NAME NAME,SYSTYPES.NAME TYPE,SYSCOLUMNS.ISNULLABLE NULLABLE,SYSCOLUMNS.LENGTH LENGTH,PRIMARYINFO.ISPRAMARY FROM SYSCOLUMNS LEFT JOIN PRIMARYINFO ON PRIMARYINFO.COLUMNNAME=NAME LEFT JOIN SYSTYPES ON SYSCOLUMNS.XUSERTYPE = SYSTYPES.XUSERTYPE WHERE SYSCOLUMNS.ID = OBJECT_ID(#{tableName})
SELECT B.name AS NAME,C.value AS DESCRIPTION FROM sys.tables A INNER JOIN sys.columns B ON B.object_id = A.object_id LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id WHERE A.name = #{tableName}
SELECT top 500 A.name AS TABLE_NAME,B.name AS COLUMN_NAME,C.value AS DESCRIPTION FROM sys.tables A INNER JOIN sys.columns B ON B.object_id = A.object_id LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id WHERE convert(nvarchar(max),C.value) like #{searchText} OR B.name like #{searchText}
select 'TABLEDESC_SYS' as tableName, value as description, major_id as majorId from sys.extended_properties WHERE minor_id=0 and major_id=object_id(#{tableName})
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 'SCHEMA', 'dbo', 'TABLE', #{tableName}, NULL, NULL)) > 0) EXEC sp_updateextendedproperty @name = 'MS_Description', @value = #{newDesc} , @level0type = 'SCHEMA', @level0name = 'dbo' , @level1type = 'TABLE', @level1name = #{tableName} ELSE EXEC sp_addextendedproperty @name = 'MS_Description', @value = #{newDesc} , @level0type = 'SCHEMA', @level0name = 'dbo' , @level1type = 'TABLE', @level1name = #{tableName}
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 'SCHEMA', 'dbo', 'TABLE', #{tableName}, 'COLUMN', #{columnName})) > 0) EXEC sp_updateextendedproperty @name = 'MS_Description', @value = #{newDesc} , @level0type = 'SCHEMA', @level0name = 'dbo' , @level1type = 'TABLE', @level1name = #{tableName} , @level2type = 'COLUMN', @level2name = #{columnName} ELSE EXEC sp_addextendedproperty @name = 'MS_Description', @value = #{newDesc} , @level0type = 'SCHEMA', @level0name = 'dbo' , @level1type = 'TABLE', @level1name = #{tableName} , @level2type = 'COLUMN', @level2name = #{columnName}