1.select * from A where a.a='a';
执行顺序 先执行 from 在执行 where 中的东西 ,最后执行 select
2.列值连接 db2 oracle || , mysql concat(column1,'sss',column2) sqlServler使用+连接;
3. case when 表达式 then ''
when 表达式 then ''
else ''
end
4. 限制返回的行数
在oracle中使用rownum <= n 限制行数
在db2中使用fetch first 5 rows only
注意 oracle中如果使用rownum =5 是得不到第五行的,因为oracle的查询原理获取一行后赋给行号,如果行号满足条件返回否则舍弃,这样永远得不到第五行,永远是第一行号并接舍弃,所以要想得到第五行,必须得到前四行,所以查询前五行必须是<= 5;
5.null 要想判断值是否为null必须为 is null , null不能用等于=和不等于<> 和任何值比较包括null
6。按模式查询 like '%a' ......
昨天我的SQL(Microsoft SQL Server 2005 )登录不上去了,原来是出现了几个小问题,现在记录一下我的解决这几个情况的办法。(解决方法有很多种,这些只是我的解决方法,仅供参考)
查找问题的过程:(注:用windows账号还是可以登录的)
第一步:启动所有与SQL有关的服务,问题依旧;
第二步:查看windows防火墙,被默认启动了,不启动选择项被Disabled
两个提示“由于安全考虑,某些设置由组策略控制”“Windows防火墙正在使用您的域设置”,先用gpedit.msc打组策略编辑器,机算机配置--管理模板--网络--网络连接--Windows防火墙--标准配置文件,查看右边各选项属性,都是未配置状态,问题不在这里。
另外一个提示中提到域设置,域设置不可能禁用SQL Server,并且我查看本地开放端口(net start ),25,1433,1434都是开发状态。
晕,会不会是密码错误?
问题一、忘记了登录Microsoft SQL Server 2005 的sa的登录密码
解决方法:先用windows身份验证的方式登录进去,然后在‘安全性’-‘登录’-右键单击‘sa’-‘属性’,修改密码点击确定就可以了。
问题二、已成功与服务器建立连接,但是在登录过程 ......
在windows2003下面安装SQL Server2000,会提示windows不支持SQL Server2000的版本,安装后,在本机是可以正常使用的,但是无法连接到其他SQL Server2000的服务器,也无法通过其他机器上的SQL Server2000访问,必须安装SQL Server2000sp3或sp4补丁才可以。其实用SQL Server2005就没这么麻烦了。 ......
On BULK COLLECT
By Steven Feuerstein Oracle ACE
Best practices for knowing your LIMIT and kicking %NOTFOUND
I have started using BULK COLLECT whenever I need to fetch large volumes of data. This has caused me some trouble with my DBA, however. He is complaining that although my programs might be running much faster, they are also consuming way too much memory. He refuses to approve them for a production rollout. What's a programmer to do?
The most important thing to remember when you learn about and start to take advantage of features such as BULK COLLECT is that there is no free lunch. There is almost always a trade-off to be made somewhere. The tradeoff with BULK COLLECT, like so many other performance-enhancing features, is "run faster but consume more memory."
Specifically, memory for collections is stored in the program global area (PGA), not the system global area (SGA). SGA memory is shared by all sessions connected to Oracle Database, but PGA memory is allocated fo ......
linq to sql 在插入值的时候还是很方便。有时候我们需要在插入一个新的实体之后得到那个实体的主键ID的值,这个ID当然必须是自增。一段时间我一直认为直接使用linq to sql的插入机制是不可以在做到的,所以只有使用存储过程的,具体可以查看这篇文章:http://blog.benhall.me.uk/2008/01/custom-insert-logic-with-linq-to-sql.html,但是总是觉得这样太麻烦了。通过观察linq to sql插入之后产生的sql发现,它自动生成了两条语句,一条insert,一条select,而且那条select正好就是查询的最后生成的主键ID,真是不可思议呀。。
下面以一个实际的代码演示一下:
1.新建一个新闻表:
列名 数据类型 允许为NULL 默认值 主键
----------------------------------------------------------------------------
ID &nbs ......
DECLARE @temp TABLE(
id INT,
[name] VARCHAR(50),
class VARCHAR(50)
)
INSERT INTO @temp
SELECT 1,'a','A'
UNION ALL SELECT 2,'b','C'
UNION ALL SELECT 3,'c','B'
UNION ALL SELECT 4,'d','C'
UNION ALL SELECT 5,'e','B'
UNION ALL SELECT 6,'f','A'
SELECT * from @temp AS _temp WHERE [name] IN
(
SELECT TOP 1 [name] from @temp WHERE _temp.class=class ORDER BY id DESC
)
ORDER BY class ......