Skip to content

Instantly share code, notes, and snippets.

@hafuu
Created July 4, 2012 06:23
Show Gist options
  • Select an option

  • Save hafuu/3045709 to your computer and use it in GitHub Desktop.

Select an option

Save hafuu/3045709 to your computer and use it in GitHub Desktop.
コメントをテーブル名、カラム名にする
SELECT
tables.name
, columns.name
, table_comments.value
, column_comments.value
, 'EXEC sp_rename ''' + CONVERT(varchar, tables.name) + '.' + CONVERT(varchar, columns.name) + ''', ''' + CONVERT(varchar, column_comments.value) + ''' , ''COLUMN'';'
FROM
sys.tables AS tables
INNER JOIN sys.columns AS columns ON
tables.object_id = columns.object_id
INNER JOIN sys.extended_properties AS table_comments ON
tables.object_id = table_comments.major_id
AND table_comments.minor_id = 0
INNER JOIN sys.extended_properties AS column_comments ON
columns.object_id = column_comments.major_id
AND columns.column_id = column_comments.minor_id
ORDER BY
tables.object_id
, columns.column_id
SELECT
tables.name
, table_comments.value
, 'EXEC sp_rename ''' + CONVERT(varchar, tables.name) + ''', ''' + CONVERT(varchar, table_comments.value) + ''';'
FROM
sys.tables AS tables
INNER JOIN sys.extended_properties AS table_comments ON
tables.object_id = table_comments.major_id
AND table_comments.minor_id = 0
ORDER BY
tables.object_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment