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

外连接sql的一个问题

当在内连接查询中加入条件时,无论是将它加入到join子句,还是加入到where子句,其效果是完全一样的,但对于外连接情况就不同了。当把条件加入到 join子句时,会返回外连接表的全部行,然后使用指定的条件返回第二个表的行。如果将条件放到where子句中,将会首先进行连接操作,然后使用where子句对连接后的行进行筛选。例如:
(1)
select u.id, u.p_plan_id, u.unit_name, p.id, p.plan_name
  from t_baidu_p_units u
  left outer join t_baidu_p_plans p on u.p_plan_id = p.id
                                   and p.id = 3176
 where 1 = 1
 order by u.p_plan_id desc
它会返回t_baidu_p_units表中所有行,t_baidu_p_plans表中符合join条件的字段不为null
(2)
select u.id, u.p_plan_id, u.unit_name, p.id, p.plan_name
  from t_baidu_p_units u
  left outer join t_baidu_p_plans p on u.p_plan_id = p.id
                                   and p.id = 3176
 where p.id is null
 order by u.p_plan_id desc
查询的结果集中没有符合join条件的数据
(3)
select u.id, u.p_plan_id, u.unit_name, p.id, p.plan_name
  from t_baidu_p_units u
  left outer join t_baidu_p_plans p on u.p_plan_id = p.id
                                   and p.id = 3176
 where p.id is not null
 order by u.p_plan_id desc
结果集中只包含join条件的数据
分析一下:
  (1)where1=1对其进行过滤时,由于都符合此条件,因此没有改变结果集
  (2)根据where p.id is null对于join后的结果集进行筛选,凡是p.id不为null的都要过滤掉,因此自然没有p.id=3176的结果
  (


相关文档:

防止SQL注入

原文地址:http://hi.baidu.com/%BC%D9%BA%EC%D2%B6%CE%E8%CE%F7%B7%E7/blog/item/81f35da209e287abcbefd005.html
1. 什么是SQL注入
所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。通过递交参数构造巧妙的SQL语句,从而成功获取想要的数据。
......

SQL参数化

SqlCommand com = new SqlCommand("select * from myuser where username=@UserName and password=@Pwd", con);
           
            com.Parameters.Add(new SqlParameter("@UserN ......

SQL Server 2005新特性,部分备份(partial backup)

也是SQL Server 2005带来的新特性,部分备份(partial backup)自动创建数据库中主文件组和所有激活读写功能的文件组的备份。如果备份存在只读文件组的数据库,部分备份将只对主文件组进行备份。这个选项对于那些存在只读文件组的超大型数据库是理想的,它不需要像那些可写的文件组备份得那么频繁。
除了需要指定READ_WRIT ......

ASP.NET SQL 注入解决方案

任何一种使用数据库web程序(当然,也包括桌面程序)都有被SQL注入的风险。防止被SQL注入,最基本的方法是在代码级别就要阻止这种可能,这个网上讲的很多,我就不多说了。不过如果你拿到的是一个已经完工的产品,这个时候该如何解决呢?我介绍几种对于ASP和ASP.NET有效的防止SQL注入的方案,而且是免费的。
UrlScan 3.1
......

Sql Server 自動還原解決方案

根據前一篇關於自動備份的文章,對應的自動還原方案
create procedure [dbo].[sp_RestoreDatabase]
@SourceDirBackupFiles NVARCHAR(200)
as
declare @DatabaseName sysname
--Table to hold the result from RESTORE HEADERONLY. Needed to get the database name o ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号