---------------------------------------------------------------- -- Author :fredrickhu(我是小F,向高手学习) -- Date :2009-10-10 13:22:00 -- Version: -- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) -- Nov 24 2008 13:01:59 -- Copyright (c) 1988-2005 Microsoft Corporation -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1) -- ---------------------------------------------------------------- --> 测试数据:[A] if object_id('[A]') is not null drop table [A] go create table [A]([ID] int,[name] varchar(4),[age] int) insert [A] select 1,'张三',12 --> 测试数据:[B] if object_id('[B]') is not null drop table [B] go create table [B]([ID] int,[name] varchar(4),[age] int) insert [B] select 1,'李四',15 --------------开始查询--------------------------select * from [A] union all select * from [B] ----------------结果---------------------------- /* ID name age ----------- ---- ----------- 1 张三 12 1 李四 15(2 行受影响)*/
UNION ALL
SELECT * FROM B
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-10-10 13:22:00
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[A]
if object_id('[A]') is not null drop table [A]
go
create table [A]([ID] int,[name] varchar(4),[age] int)
insert [A]
select 1,'张三',12
--> 测试数据:[B]
if object_id('[B]') is not null drop table [B]
go
create table [B]([ID] int,[name] varchar(4),[age] int)
insert [B]
select 1,'李四',15
--------------开始查询--------------------------select * from [A]
union all
select * from [B]
----------------结果----------------------------
/* ID name age
----------- ---- -----------
1 张三 12
1 李四 15(2 行受影响)*/
union all
SELECT * FROM 表B?
UNION ALL
select * from B