/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu

Wednesday, June 18, 2014

Using SP_MSFOREACHTABLE in sql server for updating common column in all tables

--------------- Query for updating in the existing table common column in all the tables -----------------

EXEC SP_MSFOREACHTABLE'
DECLARE @TBLNAME VARCHAR(255);
SET @TBLNAME =  PARSENAME("?",1);
DECLARE @SQL NVARCHAR(1000);

IF EXISTS(
 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
 WHERE TABLE_NAME = @TBLNAME AND COLUMN_NAME = ''ISDELETED''
)
BEGIN      
SET @SQL = N''ALTER TABLE '' +  @TBLNAME + N'' ALTER COLUMN ISDELETED BIT NOT NULL;''      
EXEC SP_EXECUTESQL @SQL
END'

No comments:

Post a Comment

My Blog List