スクリプトを使用して列の説明を変更/更新およびドロップ/削除する方法はありますか?
以前はsp_addextendedproperty
説明を追加していましたが、更新できません。同じ sp を使用して既存の説明値を更新しようとすると、「説明プロパティは既に存在します」のようなメッセージが表示されます
ソリューションのような変更またはドロップ/作成の両方は、私にとっては問題ありません。
解決
役立つ回答とコメントの後、私の最終的な解決策を以下に示します。誰かを助けるかもしれません。
create procedure sp_set_column_description (
@schema varchar(256),
@table varchar(256),
@column varchar(256),
@description varchar(256))
as
begin
if exists (
select p.*
from
sys.extended_properties p,
sys.columns c,
sys.tables t,
sys.schemas s
where
t.schema_id = s.schema_id and
c.object_id = t.object_id and
p.major_id = t.object_id and
p.minor_id = c.column_id and
p.name = N'MS_Description' and
s.name = @schema and
t.name = @table and
c.name = @column
)
exec sys.sp_updateextendedproperty
@level0type=N'SCHEMA', @level0name=@schema,
@level1type=N'TABLE', @level1name=@table,
@level2type=N'COLUMN', @level2name=@column,
@name=N'MS_Description', @value=@description
else
exec sys.sp_addextendedproperty
@level0type=N'SCHEMA', @level0name=@schema,
@level1type=N'TABLE', @level1name=@table,
@level2type=N'COLUMN', @level2name=@column,
@name=N'MS_Description', @value=@description
end
go
create procedure sp_drop_column_description (
@schema varchar(256),
@table varchar(256),
@column varchar(256))
as
begin
if exists (
select p.*
from
sys.extended_properties p,
sys.columns c,
sys.tables t,
sys.schemas s
where
t.schema_id = s.schema_id and
c.object_id = t.object_id and
p.major_id = t.object_id and
p.minor_id = c.column_id and
p.name = N'MS_Description' and
s.name = @schema and
t.name = @table and
c.name = @column
)
exec sys.sp_dropextendedproperty
@level0type=N'SCHEMA', @level0name=@schema,
@level1type=N'TABLE', @level1name=@table,
@level2type=N'COLUMN', @level2name=@column,
@name=N'MS_Description'
end