SQLServer 벌크 추가 필드 주석

1500 단어
제목과 같이 먼저 테이블 유형을 정의합니다.
CREATE TYPE column_comments AS TABLE(column_name VARCHAR(200),comment VARCHAR(1000))

그런 다음 스토리지 프로세스를 정의합니다.
CREATE PROC sp_add_comments @tmp_column_comments column_comments READONLY, @tb_name VARCHAR(200) AS
DECLARE @column_name VARCHAR(200), @comment VARCHAR(1000)
DECLARE c_cms CURSOR LOCAL FOR SELECT * FROM @tmp_column_comments
OPEN c_cms
FETCH NEXT FROM c_cms INTO @column_name, @comment
WHILE @@FETCH_STATUS = 0
BEGIN
    IF (SELECT COUNT(1) FROM fn_listextendedproperty('MS_Description', 'SCHEMA', 'dbo', 'TABLE', @tb_name, 'COLUMN', @column_name)) > 0
        EXEC sp_updateextendedproperty @name = 'MS_Description', @value = @comment, @level0type = 'SCHEMA', @level0name = 'dbo', @level1type = 'TABLE', @level1name = @tb_name, @level2type = 'COLUMN', @level2name = @column_name
    ELSE
        EXEC sp_addextendedproperty @name = 'MS_Description', @value = @comment, @level0type = 'SCHEMA', @level0name = 'dbo', @level1type = 'TABLE', @level1name = @tb_name, @level2type = 'COLUMN', @level2name = @column_name
    FETCH NEXT FROM c_cms INTO @column_name, @comment
END
CLOSE c_cms
DEALLOCATE c_cms
호출 방법은 다음과 같습니다.
DECLARE @tmp_cms column_comments
INSERT INTO @tmp_cms VALUES('id','  ID')
EXEC sp_add_comments @tmp_cms, 'table_test'

EOF.

좋은 웹페이지 즐겨찾기