SQL Server 复制表

INSERT INTO new_table SELECT * FROM old_table;
把old_table表的数据插到new_table表上,
但前提是,这个new_table表必须存在且结构和old_table表的一样

SELECT * INTO new_table FROM old_table;
新建new_table表且把old_table表的结构及数据全部复制进去

SELECT * INTO new_table FROM old_table WHERE 1=2;
新建一个结构和old_table表一样的new_table表

INSERT INTO new_table(c1, c2, c3) SELECT c1, c2, c3 FROM old_table
选择字段复制,当然然后可以加WHERE条件限制

继续阅读

展现一下今天写的两条SQL语句

SELECT `strb_prod_id` as ProdId, `goods_id`, `goods_name`, `goods_number`, `market_price` FROM `qx_good_strb_stock` q,`ecs_goods` g WHERE g.is_on_sale=1 and q.qx_good_id=g.goods_id;
SELECT g.`goods_id`, g.`goods_name`, g.`shop_price`, q.`SellingPrice` FROM `ecs_goods` g, `qx_out_goods_data` q WHERE q.shuai=1 AND q.qx_good_id=g.goods_id;

悲哀呀,最近写SQL写到想吐了!!!!!!!!!!!!!!!!!!!!!!

继续阅读