SQL 常用



插入
//基本插入
insert into DB_A (a,b) select a,b from DB_B
//表拷贝
insert into b select * from a 


更新
//单表数据更新
update DB_A  set a= '0' 
//一对多筛选更新 
update DB_A  set a=(select top 1 a from DB_B where DB_B.b=DB_A  .b)


合并数据
SELECT a, b= REPLACE( (SELECT b AS [data()]   
                        FROM DB_B AS b    
                        WHERE b.c= a.c
                        FOR XML PATH('')) , ' ', ' ')   
FROM DB_A   AS a     
GROUP BY a 


你可能感兴趣的:(SQL 常用)