--------------- 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'
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