-- append tables which you want to import Insert Into @tbImportTables(tablename, deleted) values("tentitytype", 1) Insert Into @tbImportTables(tablename, deleted) values("tattribute", 1) -- append all tables --Insert Into @tbImportTables(tablename, deleted) select table_name, 1 from INFORMATION_SCHEMA.tables where table_type = "BASE TABLE"
set @fieldscript = "" select @fieldscript = @fieldscript + column_name + "," from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in("timestamp", "image") set @fieldscript = substring(@fieldscript, 0, len(@fieldscript))
set @valuescript = "" select @valuescript = @valuescript + "case when " + column_name + " is null then ""null"" else """""""" + convert(varchar(max), " + column_name + ") + """""""" end +"",""+" from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in("timestamp", "image") set @valuescript = substring(@valuescript, 0, len(@valuescript) - 4)
set @insertscript = "select ""insert into " + @tablename + "(" + @fieldscript + ") values(" + """+" + @valuescript + " + "")"" from " + @tablename Insert into @tbImportScripts(script) exec ( @insertscript)