Home > database >  Create a view, more than 100 tables, table structure is the same, in addition to I write the followi
Create a view, more than 100 tables, table structure is the same, in addition to I write the followi

Time:10-17

My table has 128 copies, according to the writing too much trouble, could you tell me is there any simple way, please teach a great god,

CodePudding user response:

Circulation after mosaics of the exec

CodePudding user response:


 
/*
Precommand with one table structure to create a temporary table
Command1 write check each table query results? Said to satisfy conditions table
Whereand get what you need to collect the table name
Postcommand is query data of temporary tables, and drop the temporary table
*/
The exec sp_MSForEachTable
@ precommand="select Top into 0 * # # TMP from table 1",
@ command1="insert # # TMP select * from?" ,
@ whereand="and o.n ame like '%' table and o.t ype='U'",
@ postcommand="
Select * from # # TMP
Drop table # # TMP "

  • Related