日期:2014-05-17 浏览次数:20640 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-03-14 17:29:45
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[a]
if object_id('[a]') is not null drop table [a]
go
create table [a]([ID] varchar(1),[type] varchar(4))
insert [a]
select 'a','111' union all
select 'b','222' union all
select 'c','fdsa'
--------------开始查询--------------------------
--> 测试数据:[b]
if object_id('[b]') is not null drop table [b]
go
create table [b]([id] varchar(3),[type] int)
insert [b]
select 'a',111 union all
select 'b',222 union all
select 'fda',555 union all
select 'a',33 union all
select 'b',111
--------------开始查询--------------------------
select * INTO #t FROM (
select * from [b]
except
select * from [a])a
TRUNCATE TABLE b
INSERT INTO b
SELECT * FROM #t
DROP TABLE #t
----------------结果----------------------------
/*
*/