update ctry set page='1206' update ctry set subpage='120601' if exists(select * from sys.tables where name = 'ctry') begin declare @table as nvarchar(100) = 'ctry' declare @column as nvarchar(100) = '' declare @datatype as nvarchar(100) = '' declare cur cursor local for select col.name columnname, type_name(user_type_id) + case when type_name(user_type_id) in ('char', 'nchar', 'varchar', 'nvarchar') then case when isnull(max_length, 0) < 0 then '(max)' else '(' +convert(varchar, isnull(max_length, 0)) +')' end else '' end + case when type_name(user_type_id) in ('decimal', 'numeric') then ' (' + convert(varchar, [precision]) + ', ' + convert(varchar, scale) + ')' else '' end datatype from sys.columns col where object_name(col.object_id) = @table and isnull(col.is_nullable, 0) = 1 open cur fetch next from cur into @column, @datatype while @@FETCH_STATUS = 0 begin exec('alter table ' + @table + ' alter column ' + @column + ' ' + @datatype + ' not null') fetch next from cur into @column, @datatype end end |GO| ----------------------------------------------------------------------------------------------------------------------------------- if exists(select * from sys.tables where name = 'ctry') begin declare @table as nvarchar(100) = 'ctry' declare @constraint as nvarchar(100) = '' declare @column as nvarchar(100) = '' declare cur cursor local for select object_name(cons.parent_object_id) tablename, object_name(cons.object_id) constraintname, col.name columnname from sys.default_constraints cons inner join sys.columns col on cons.parent_object_id = col.object_id and cons.parent_column_id = col.column_id where object_name(cons.parent_object_id) = @table open cur fetch next from cur into @table, @constraint, @column while @@FETCH_STATUS = 0 begin exec('alter table ' + @table + ' drop constraint ' + @constraint) fetch next from cur into @table, @constraint, @column end end |GO| alter table ctry add creglobalid bigint alter table ctry add updglobalid bigint alter table ctry Add cremedium tinyint alter table ctry Add creverno varchar(500) alter table ctry Add crepatchno varchar(20) alter table ctry Add cresessionid bigint alter table ctry Add crekey varchar(50) alter table ctry Add updmedium tinyint alter table ctry Add updverno varchar(500) alter table ctry Add updpatchno varchar(20) alter table ctry Add updsessionid bigint alter table ctry Add updkey varchar(50) alter table ctry Add block varchar(50) |GO| update ctry set creglobalid = 0 where creglobalid is null update ctry set updglobalid = 0 where updglobalid is null update ctry set cremedium = 1 where cremedium is null update ctry set creverno = (Select top 1 dbversion From <>.dbo.appversion) where creverno is null update ctry set crepatchno = '' where crepatchno is null update ctry set cresessionid = 0 where cresessionid is null update ctry set crekey = '' where crekey is null update ctry set updmedium = 1 where updmedium is null update ctry set updverno = (Select top 1 dbversion From <>.dbo.appversion) where updverno is null update ctry set updpatchno = '' where updpatchno is null update ctry set updsessionid = 0 where updsessionid is null update ctry set updkey = '' where updkey is null update ctry set block = '' where block is null |GO| alter table ctry Alter Column creglobalid bigint Not Null alter table ctry Alter Column updglobalid bigint Not Null alter table ctry Alter Column cremedium tinyint Not Null alter table ctry Alter Column creverno varchar(500) Not Null alter table ctry Alter Column crepatchno varchar(20) Not Null alter table ctry Alter Column cresessionid bigint Not Null alter table ctry Alter Column crekey varchar(50) Not Null alter table ctry Alter Column updmedium tinyint Not Null alter table ctry Alter Column updverno varchar(500) Not Null alter table ctry Alter Column updpatchno varchar(20) Not Null alter table ctry Alter Column updsessionid bigint Not Null alter table ctry Alter Column updkey varchar(50) Not Null alter table ctry Alter Column block varchar(50) Not Null |GO|