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

SQLServer数据集合的交、并、差集运算

 SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算。
他们的对应关系可以参考下面图示
       相关测试实例如下:
use tempdb
go
if (object_id ('t1' ) is not null ) drop table t1
if (object_id ('t2' ) is not null ) drop table t2
go
create table t1 (a int )
insert into t1 select 1 union select 2 union select 3
create table t2 (a int )
insert into t2 select 3 union select 4 union select 5
go
select * from t1 union select * from t2
go
/* 求表并集
1
2
3
4
5*/
select * from t1 union all   select * from t2
go
/*求表并集不过滤重复
1
2
3
3
4
5*/
select * from t1 except select * from t2
go
/*求t1对t2的差集
1
2*/
select * from t1 intersect select * from t2
go
/*求t1对t2的交集
3*/
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jinjazz/archive/2009/09/07/4527863.aspx


相关文档:

12本sqlserver电子书


SQL Server 2008 Administration Instant Reference

SQL Server 2005 数据库基础与应用技术

Microsoft SQLServer 2005 Integration Services Step by Step

SQLServer 2005 Bible

SQL Server 2005 数据库服务架构设 ......

SQLServer批量倒入目录文件 收藏


可以用扩展存储过程xp_dirtree获取文件列表,用openrowset倒入数据到二进制字段。
openrowset的用法可以参考msdn
http://technet.microsoft.com/zh-cn/library/ms190312.aspx
如果文件很多,建议还是用程序倒入了
if (object_id ('t_bulkResult' ) is   not   null )
drop table t_bulkResult ......

SQLServer2005分解并导入xml文件

  SQLServer2005分解并导入xml文件 收藏
测试环境SQL2005,windows2003
DECLARE @idoc int;
DECLARE @doc xml;
 
SELECT @doc=bulkcolumn from OPENROWSET(
   BULK 'D: \test.xml',
   SINGLE_BLOB) AS x
 
EXEC sp_xml_preparedocument @Idoc OUTPUT, @doc
 
  ......

SQLSERVER自增主键

SQLServer 中含自增主键的表,通常不能直接指定ID值插入,可以采用以下方法插入。
1. SQLServer 自增主键创建语法:
identity(seed, increment)
其中
seed 起始值
increment 增量
示例:
create table student(
      id int identity(1,1),
      name varcha ......

用CASE WHEN实现sqlserver数据库的分类汇总功能

/*用CASE WHEN实现sqlserver数据库的分类汇总功能*/
/*例1:统计个数*/
/*表结构
id  cityid  major
1   1         A
2   1         B
3   2        ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号