Select 'if
not exists (select * from syscolumns
where
id=object_id('''+TableName+''') and name='''+ColumnName+''')
alter
table '+TableName+' add '+ColumnName+' '+Datatype+' NULL '+ CHAR(13)+CHAR(10) +'
' as SS, * from (
SELECT
c.name 'ColumnName',
Case when t.Name='nvarchar' then t.Name +'(' + CAST(c.max_length AS varchar) +')' else t.Name end as 'Datatype',
c.max_length 'MaxLength',
c.precision ,
c.scale ,
c.is_nullable,
ISNULL(i.is_primary_key, 0) 'PrimaryKey',
Object_Name(c.object_id) AS TableName,
c.object_id
FROM
sys.columns c
INNER JOIN
sys.types t ON c.user_type_id = t.user_type_id
LEFT OUTER JOIN
sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
LEFT OUTER JOIN
sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
WHERE
c.object_id>100
--c.object_id =
OBJECT_ID('UrunAlimSatim')
) as T where
T.TableName not like ('Grn%')
and T.TableName not like ('Vw%')
and T.TableName not like ('plan_%')
and T.TableName not like ('Get%')
and T.TableName not like ('Rhb%')
and T.TableName not like ('V_%')
and T.TableName not like ('SL%')
and T.TableName not like ('rpt%')
and T.TableName not like ('sqlagent%')
and T.TableName not like ('queue%')
and T.TableName not like ('sys%')
and T.TableName not like ('filestream%')
and T.TableName not like ('file%')
and T.TableName not like ('SeansSaatParam1%')
and T.TableName not like ('takas_gelen%')
and T.TableName not like ('Takas')
and T.TableName not like ('TakasSonucTMOIlk')
and T.TableName not like ('TakasSonucTMO')
and T.TableName not like ('Takas_')
and T.TableName not like ('SeansSonuc')
and T.TableName not like ('TblTmoEmirGelenMurat')
and T.TableName not like ('Takas')
ORDER by object_id
Hiç yorum yok:
Yorum Gönder