易截截图软件、单文件、免安装、纯绿色、仅160KB

[Sql]EXCEPT 和 INTERSECT关键字

[Sql]EXCEPT 和 INTERSECT关键字
http://www.cnblogs.com/treeyh/archive/2008/07/01/1232845.html
EXCEPT
从 EXCEPT 操作数左边的查询中返回右边的查询未返回的所有非重复值。
INTERSECT
返回 INTERSECT 操作数左右两边的两个查询均返回的所有非重复值。
A. 使用 EXCEPT
在示例中使用 TableA 和 TableB 中的数据。
TableA (col1 int)
TableB (col1 int)

NULL
NULL
NULL
1
NULL
3
1
4
2
4
2
2
3
4
4
以下查询从 EXCEPT
操作数左侧的查询返回右侧查询没有找到的所有非重复值。


SELECT * from TableA EXCEPT
SELECT * from TableB;
下面是结果集: 


Col1
-----------
2
(1 row(s) affected)
B. 使用 INTERSECT
在示例中使用 TableA 和 TableB 中的数据。
TableA (col1 int)
TableB (col1 int)

NULL
2
NULL
2
NULL
2
1
4
2
4
2
2
3
4
4
以下查询返回 INTERSECT
操作数左右两侧的两个查询均返回的所有非重复值。


SELECT * from TableA INTERSECT
SELECT * from TableB;
下面是结果集: 


Col1
-----------
2
4
(2 row(s) affected)


相关文档:

SQL UNION 和UNION ALL 操作符


SQL UNION 操作符
UNION 操作符用于合并两个或多个 SELECT 语句的结果集。
请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。
SQL UNION 语法
SELECT column_name(s) from table_name1
UNION
SELECT column_name(s) from table_na ......

SQL中declare申明变量

在sql语句中添加变量。
declare @local_variable data_type
声明时需要指定变量的类型,
可以使用set和select对变量进行赋值,
在sql语句中就可以使用@local_variable来调用变量
声明中可以提供值,否则声明之后所有变量将初始化为NULL。
例如:declare @id int
       &nb ......

sql附加数据库只读问题

在SQL Server 2005 Express 上附加从另外一台电脑Copy过来的数据库后,数据库为“只读”。 
解决办法:
打开 SQL Server Configuration Manager, 打开SQL Server SQLEXPRESS 的属性
在内置帐号处,把“网络服务”改成“本地系统”,重新启动SQL Server 2005 Express 后,再附加数据 ......

Rebuild indexes online with SQL Server 2005

Rebuild indexes online with SQL Server 2005
http://blogs.techrepublic.com.com/datacenter/?p=249
Online index rebuild
SQL Server 2005 introduces the ability to rebuild your indexes in an
online fashion so that other processes are able to access the table
while the rebuild is occurring. Because y ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号