34,836
社区成员




DECLARE @sql VARCHAR(max)=''
SELECT @sql=@sql+'execute sp_addextendedproperty ''MS_Description'',''XXXX'',''user'',''dbo'',''table'','''+name+''',null,null;'+CHAR(10)+'go'+CHAR(10) FROM sys.objects WHERE type='U'
PRINT @sql
你在拼SQL字符串的时候,加个 CHAR(10)+'go'+CHAR(10),这样,每句sql后面都有个go了
DECLARE @SQL VARCHAR(1000)
SET @SQL='execute sp_addextendedproperty ''MS_Description'',
''接收时间'',
''user'', ''dbo'', ''table'', ''BS_Track_Info'', ''column'', ''RecieveTime'';
execute sp_addextendedproperty ''MS_Description'',
''接收时间'',
''user'', ''dbo'', ''table'', ''BS_Track_Info'', ''column'', ''RecieveTime'';
execute sp_addextendedproperty ''MS_Description'',
''主键'',
''user'', ''dbo'', ''table'', ''BS_Track_Info'', ''column'', ''id'''
exec(@SQL)
--1.
BEGIN TRY
execute sp_addextendedproperty 'MS_Description','XXXX','user','dbo','table','TB1',null,null;
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS ErrorMessage
END CATCH
--2.
BEGIN TRY
execute sp_addextendedproperty 'MS_Description','XXXX2','user','dbo','table','TB2',null,null;
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS ErrorMessage
END CATCH