CREATE PROCEDURE [dbo].[BatchDeleteTableField]
@ColumnName VARCHAR(50)
AS
BEGIN
DECLARE @sql VARCHAR(2000)
DECLARE @Name VARCHAR(50)
DECLARE bDTF CURSOR FOR (SELECT T1.name FROM SYSOBJECTS T1 WHERE T1.xtype='U' )
OPEN bDTF
FETCH NEXT FROM bDTF INTO @Name
WHILE @@FETCH_STATUS=0
BEGIN
IF EXISTS (SELECT 1 FROM SYSOBJECTS T1 INNER JOIN SYSCOLUMNS T2 ON T1.ID=T2.ID WHERE T1.NAME=@Name AND T1.xtype='U' AND T2.NAME=@ColumnName)
BEGIN
SET @sql='ALTER TABLE '+@Name+' DROP COLUMN ' +@ColumnName
EXEC(@sql)
END
FETCH NEXT FROM bDTF INTO @Name
END
CLOSE bDTF
DEALLOCATE bDTF
END