SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

Declare @tableName nvarchar(500)

--遍历信息表
DECLARE listData CURSOR FOR  SELECT [name] FROM [pa_info_table]
OPEN listData
fetch next from listData INTO @tableName
WHILE @@FETCH_STATUS=0
Begin

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(@tableName) AND type in (N'U'))
BEGIN
IF Not EXISTS (select * from syscolumns where id=object_id(@tableName) and name='ip')
Begin
/*创建ip字段*/
exec('ALTER TABLE ['+@tableName+'] ADD [ip] varchar(150)')
exec('update ['+@tableName+'] set ip=''127.0.0.1''')
END
END

fetch next from listData INTO @tableName
END
CLOSE listData 
DEALLOCATE listData



SET ANSI_PADDING OFF
GO

