1:复制表结构
select * into 数据库1.dbo.table1 from 数据库2.dbo.table2 where (1=2)
2:复制表(包括结构和数据)
select * into 数据库1.dbo.table1 from 数据库2.dbo.table2 where (1=1)
3.从一个表中分组统计信息,插入新表中
select productcode ,count(*) as quantity into tempquantity from inventorylocation where grade='3' and del='0' and booknumber like '02%' and productcode like '9787%' and locationnumber is not null group by productcode
4 ,把一个表中的数据更新到另外一个表中是sql。
update inventoryinfo set inventoryinfo.quantity = tempquantity.quantity
from inventoryinfo inner join tempquantity
on inventoryinfo.productcode = tempquantity.productcode where grade='3' and inventoryinfo.quantity>tempquantity.quantity