"Traverse all tables, copy table structure, copy table data"
--INSERT statement
SELECT into from B is in the absence of a table, directly through the B table to create and copy the B table data into a table, and then the structure and data of the A/b table is exactly the same.
into Select from b is in the case of a table has been created, the B table data copied to a table, before the structure of a table is the same as the B table, or inserted when the error.
--Copy the table structure to the new library
SELECT into from DBTest.dbo.table1
--Query all table names in the library
SELECT from WHERE xtype=' U '
--SELECTfromWHERE type=' U '
--traverse all tables in the library and execute the specified SQL for all tables in bulk
Declare@tb_name nvarchar (100)
Declare@iint
Declare@tbTable(IDint Identity(+), name nvarchar (1000))
Set@i = 1
Set@tb_name =' CX '--All tables starting with this value
Insert into@tb (name)
SelectT.name
fromsysobjects T
whereXtype=' u ' andT.name like@tb_name +'% '
while@i <= (Select COUNT(*) from@tb)
begin
Select@tb_name = Name from@tbwhereid = @i;
exec(' select * from '[Email Protected]_name];
Set@i = @i + 1
End
SQL notes [long-term update] (-2015.4)