﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-太行年华-随笔分类-技术热点</title><link>http://www.cnitblog.com/taihang/category/2472.html</link><description>一步步走过每一片绿色</description><language>zh-cn</language><lastBuildDate>Mon, 03 Oct 2011 10:56:55 GMT</lastBuildDate><pubDate>Mon, 03 Oct 2011 10:56:55 GMT</pubDate><ttl>60</ttl><item><title>求助:装上卡巴斯基6.0为什么不能看到收取邮件的内容?</title><link>http://www.cnitblog.com/taihang/archive/2007/01/12/21820.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Fri, 12 Jan 2007 08:07:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2007/01/12/21820.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/21820.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2007/01/12/21820.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/21820.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/21820.html</trackback:ping><description><![CDATA[装上卡巴斯基6.0为什么不能看到收取邮件的内容?从设置里把邮件保护都去掉了,还是不行,邮件的内容显不出来,只能退了卡巴以后才可以正常使用邮件,我用的邮件是163的<img src ="http://www.cnitblog.com/taihang/aggbug/21820.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2007-01-12 16:07 <a href="http://www.cnitblog.com/taihang/archive/2007/01/12/21820.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-程序设计基础-游标</title><link>http://www.cnitblog.com/taihang/archive/2006/06/23/12749.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Fri, 23 Jun 2006 06:11:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/23/12749.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12749.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/23/12749.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12749.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12749.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">内容繁多，不易记呀!<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />游标的引入<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.在数据的开发过程中，从某一结果集中逐一读取一条记录，用游标解决，游标占资源大，确定不用后将其释放。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.声明游标（四个组成部分）<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).declare游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).open游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).从一个游标中fetch信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">).close或deallocate游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />一、声明游标主要内容：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).游标名字<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).数据来源表和列<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).选取条件<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">).属性仅读或可修改<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.语法格式：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> 游标名称 </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">scroll</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">local|global</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">forward_only|scroll</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> 选择语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">for[read_only|update [of 字段名称1，字段名称2，<img src="http://www.cnitblog.com/images/dot.gif" /></span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">]]<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.local</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">global指定该游标的作用域是局部的还是全局的。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.如果把forward_only选择为forward_only, 则游标只能从第一行滚动到最后一行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.scroll表明所有的提取操作，如first,last,prior,</span>
				<span style="COLOR: #0000ff">next</span>
				<span style="COLOR: #000000">,relative,absolute都可用。如不使用该保留字，那么只能进行next提取操作。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.选择语句：是定义结果集的select语句，应该注意的是在游标中不能使用compute,</span>
				<span style="COLOR: #0000ff">compute</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">browse</span>
				<span style="COLOR: #000000"> into语句.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #0000ff">read</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">only</span>
				<span style="COLOR: #000000">:表明不允许游标内的数据被更新。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">of 字段名1[,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">]:定义在游标中可被修改的列。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：标准游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> taihang </span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> id,name,address,city,state<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2：只读游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> taihang </span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> id,name,address,city,atate<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">read</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">only</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例3：更新游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> taihang </span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> name,address<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />二、打开游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.声明之后，如要从游标中读取数据，必须打开游标，使用open命令。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">open</span>
				<span style="COLOR: #000000">　游标名称<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意:<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.在打开游标时，如果游标声明语句中使用了insensitive保留字，则open产生一个临时表来存放结果集。如果在结果集中任何一行数据的大小超过SQL Server定义的最大行尺寸时，open命令将失败。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.insensitive:表明SQL Server会将游标定义所选取出来的数据记录存放在一临时表内，（建立在tempdb数据库下）对该游标的操作皆由临时表来应答。因此，对基本表的修改并不影响游标提取数据，即游标不会随着基本表内容的改变面改变，同时也不法通过游标来更新基本表。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />如果不使用该保留字，那么对基本表的更新，删除都会公映到游标中。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />三、读取游标中的数据－</span>
				<span style="COLOR: #0000ff">fetch</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.当游标被成功打开以后就可以从游标中逐行地读取数据以时行相关处理。从游标中读取数据主要使用fetch命令。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">fetch</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">[next|prior|first|last<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />|absolute{n|@nvar}<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />|relative{n|@nvar}</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000">] cursor_name<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">into @variable_name1,@variable_name2<img src="http://www.cnitblog.com/images/dot.gif" /></span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #0000ff">next</span>
				<span style="COLOR: #000000">:返回结果集中当前行的下一行，并增加当前行数为返回行行数。如果fetch next是第一次读取游标中数据，则返回结果集中的第一行而不是第二行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.prior:返回结果集中当前行的前一行，并减少当前行数为返回行行数。如果fetch prior是第一次读取游标中的数据，刚无数据记录返回，并把游标位置设为第一行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.first:返回游标中的第一行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.last:返回游标中的最后一行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.absolute{n</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #008000">@nvar</span>
				<span style="COLOR: #000000">}:如果N或</span>
				<span style="COLOR: #008000">@nvar为正数</span>
				<span style="COLOR: #000000">，则表示从游标中返回的数据行数。如果N或</span>
				<span style="COLOR: #008000">@nvar为负数</span>
				<span style="COLOR: #000000">，则返回游标内从最后一行数据算起的第N或</span>
				<span style="COLOR: #008000">@nvar行数据</span>
				<span style="COLOR: #000000">。若N或</span>
				<span style="COLOR: #008000">@nvar超过游标的数据子集范畴</span>
				<span style="COLOR: #000000">，则</span>
				<span style="FONT-WEIGHT: bold; COLOR: #008000">@@fetch_status返回</span>
				<span style="COLOR: #808080">-</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">。在该情况下，如果N或</span>
				<span style="COLOR: #008000">@nvar为负数</span>
				<span style="COLOR: #000000">，则再执行fetch next命令会得到第一行数据；如果N或</span>
				<span style="COLOR: #008000">@nvar为正值</span>
				<span style="COLOR: #000000">，如执行fetch prior命令刚会得到最后一行数据。N或</span>
				<span style="COLOR: #008000">@nvar可以是固定值</span>
				<span style="COLOR: #000000">，也可以是smallint,tinyint或int类型的变量。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.relative{N</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #008000">@nvar</span>
				<span style="COLOR: #000000">}:若N或</span>
				<span style="COLOR: #008000">@nvar为正数</span>
				<span style="COLOR: #000000">，则读取游标当前位置起向后的第N或</span>
				<span style="COLOR: #008000">@nvar行数据</span>
				<span style="COLOR: #000000">。如果N或</span>
				<span style="COLOR: #008000">@nvar为负数</span>
				<span style="COLOR: #000000">，则返回游标当前位置起向前的第N或</span>
				<span style="COLOR: #008000">@nvar行数据</span>
				<span style="COLOR: #000000">。若N或</span>
				<span style="COLOR: #008000">@nvar超过游标的数据子集范畴</span>
				<span style="COLOR: #000000">，则</span>
				<span style="FONT-WEIGHT: bold; COLOR: #008000">@@fetch_status返回</span>
				<span style="COLOR: #808080">-</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">。在该情况下，如果N或</span>
				<span style="COLOR: #008000">@nvar为负数</span>
				<span style="COLOR: #000000">，则再执行fetch next命令会得到第一行数据；如果N或</span>
				<span style="COLOR: #008000">@nvar为正值</span>
				<span style="COLOR: #000000">，如执行fetch prior命令刚会得到最后一行数据。N或</span>
				<span style="COLOR: #008000">@nvar可以是固定值</span>
				<span style="COLOR: #000000">，也可以是smallint,tinyint或int类型的变量。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #008000">@variable_name</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">:允许使用fetch命令读取的数据存放在多个变量中；在变量行中的每个变量必须与游标结果集中相应的列相对应，每一变量的数据类型也要与游标中的数据列的数据类型相匹配。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.检查游标状态<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #008000">@@fetch_status</span>
				<span style="COLOR: #000000">:全局变量，返回上次执行fetch命令的状态，在每次用fetch从游标中读取数据时，都应检查该变量以确定上次fetch操作是否成功，来决定如何进行下一步处理。</span>
				<span style="FONT-WEIGHT: bold; COLOR: #008000">@@fetch_status变量有三个不同返回值</span>
				<span style="COLOR: #000000">。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">0</span>
				<span style="COLOR: #000000">：表示成功取出了一行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">1表示未取到数据。游标位置超出结果集。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">2表示返回的行已经不再是结果集的一个成员，这种情况只有在游标不是insensitive的情况下出现，即其它进程已删除了行或改变了游标打开的关键值。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.编辑当前游标行<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />通常，用游标来从基础表中检索数据，以实现对数据行处理，在修改游标中的数据，即进行定位更新或删除游标所包含的数据，所以必须执行另外的更新或删除命令，并在where子句中重新给定条件才能修改到该行数据，但是如果在声明游标时使用了for update语句那么就可以在update或delete命令中以where </span>
				<span style="COLOR: #0000ff">current</span>
				<span style="COLOR: #000000"> of关键字直接修改或删除当前游标中所存储的数据，而不必使用where子句重新给出指定条件。当改变游标中数据时，这种变化会自动地影响到游标的基础表。但是如果在声明游标时选择了insensitive选项时，该游标中的数据不能被修改。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />进行定位修改或删除游标中的数据的语法规则语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> table_name<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> column_name1</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">{expression1</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">(select_statement)}<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,column_name2={expression2|null(select_statement)}</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">current</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">of</span>
				<span style="COLOR: #000000"> cursor_name<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> table_name<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">current</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">of</span>
				<span style="COLOR: #000000"> cursor_name<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.table_name：是update或delete的表名。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.column_name：uqdate的列名<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.cursor_name:游标名<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：首先声明一个游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> authors_cur scroll </span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> authors<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">of</span>
				<span style="COLOR: #000000"> au_lname,au_fname<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />更新authors表中的au_lname和au_fname列<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> authors<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> au_lname</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">china</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,au_fname</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">asia</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">current</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">of</span>
				<span style="COLOR: #000000"> authors_cur<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />删除authors表中的一行数据<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> authors<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">current</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">of</span>
				<span style="COLOR: #000000"> authors_cur<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：以上的更新或删除操作总是在游标的当前位置，<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：下面是一个完整的定位更新的例子。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@au_id</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">11</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #008000">@au_lname</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">40</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #008000">@au_fname</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">20</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> authors_cur </span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> au_id,au_lname,au_fname </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> authors<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">of</span>
				<span style="COLOR: #000000"> au_id,aulname,au_fname<br /><img id="Codehighlighter1_3669_3688_Open_Image" onclick="this.style.display='none'; Codehighlighter1_3669_3688_Open_Text.style.display='none'; Codehighlighter1_3669_3688_Closed_Image.style.display='inline'; Codehighlighter1_3669_3688_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_3669_3688_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_3669_3688_Closed_Text.style.display='none'; Codehighlighter1_3669_3688_Open_Image.style.display='inline'; Codehighlighter1_3669_3688_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">open</span>
				<span style="COLOR: #000000"> authors_cur </span>
				<span id="Codehighlighter1_3669_3688_Open_Text">
						<span style="COLOR: #008080">/*</span>
						<span style="COLOR: #008080">open then cursor</span>
						<span style="COLOR: #008080">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">fetch</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">next</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> authors_cer </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@au_id</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #008000">@au_lname</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #008000">@au_fname</span>
				<span style="COLOR: #000000">
						<br />
						<img id="Codehighlighter1_3773_3803_Open_Image" onclick="this.style.display='none'; Codehighlighter1_3773_3803_Open_Text.style.display='none'; Codehighlighter1_3773_3803_Closed_Image.style.display='inline'; Codehighlighter1_3773_3803_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_3773_3803_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_3773_3803_Closed_Text.style.display='none'; Codehighlighter1_3773_3803_Open_Image.style.display='inline'; Codehighlighter1_3773_3803_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #008000">@@fetch_status</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">0</span>
				<span style="COLOR: #000000"> </span>
				<span id="Codehighlighter1_3773_3803_Open_Text">
						<span style="COLOR: #008080">/*</span>
						<span style="COLOR: #008080">loop the rows in the cursor</span>
						<span style="COLOR: #008080">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@au_id</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">172-32-1176</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> authors<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> au_lname</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">smith</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,au_fname</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">jake</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">current</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">of</span>
				<span style="COLOR: #000000"> authors_cur<br /><img id="Codehighlighter1_3919_3934_Open_Image" onclick="this.style.display='none'; Codehighlighter1_3919_3934_Open_Text.style.display='none'; Codehighlighter1_3919_3934_Closed_Image.style.display='inline'; Codehighlighter1_3919_3934_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_3919_3934_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_3919_3934_Closed_Text.style.display='none'; Codehighlighter1_3919_3934_Open_Image.style.display='inline'; Codehighlighter1_3919_3934_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_3919_3934_Open_Text">
						<span style="COLOR: #008080">/*</span>
						<span style="COLOR: #008080">get next row</span>
						<span style="COLOR: #008080">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">fetch</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">next</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> authors_cer </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@au_id</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #008000">@au_lname</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #008000">@au_fname</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img id="Codehighlighter1_4023_4042_Open_Image" onclick="this.style.display='none'; Codehighlighter1_4023_4042_Open_Text.style.display='none'; Codehighlighter1_4023_4042_Closed_Image.style.display='inline'; Codehighlighter1_4023_4042_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_4023_4042_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_4023_4042_Closed_Text.style.display='none'; Codehighlighter1_4023_4042_Open_Image.style.display='inline'; Codehighlighter1_4023_4042_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">deallocate</span>
				<span style="COLOR: #000000"> authors_cur </span>
				<span id="Codehighlighter1_4023_4042_Open_Text">
						<span style="COLOR: #008080">/*</span>
						<span style="COLOR: #008080">close the cursor</span>
						<span style="COLOR: #008080">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />四、释放游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.关闭游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />使用close命令关闭游标，在处理完游标中数据之后，发布关闭游标来释放数据结果集和定位于数据记录上的锁，close语句关闭游标但不释放游标占用的数据结构。如果准备在随后的使用中再次打开游标，则应使用open命令。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：</span>
				<span style="COLOR: #0000ff">close</span>
				<span style="COLOR: #000000"> 游标名称<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.释放游标<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />在使用游标时各种针对游标的操作或者引用游标各或者引用指向游标的游标变量，当close命令关闭游标时并没有释放游标占用的数据结构。因此常使用deallocate命令删除掉游标与游标名或游标变量之间的联系，并且释放游标占用的所有系统资源。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：</span>
				<span style="COLOR: #0000ff">deallocate</span>
				<span style="COLOR: #000000"> 游标名称</span>
		</div><img src ="http://www.cnitblog.com/taihang/aggbug/12749.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-23 14:11 <a href="http://www.cnitblog.com/taihang/archive/2006/06/23/12749.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-程序设计基础-流程控制语句</title><link>http://www.cnitblog.com/taihang/archive/2006/06/21/12638.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Wed, 21 Jun 2006 09:14:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/21/12638.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12638.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/21/12638.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12638.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12638.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">越学越有意思，不是很难！<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />流程控制语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />流程控制语句是指那些用来控制程序执行和流程分支的命令，在SQL Server 2000中，育种控制语句主要用来控制SQL语句、语句块或者存储过程执行流程。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).</span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<img src="http://www.cnitblog.com/images/dot.gif" />end语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<img src="http://www.cnitblog.com/images/dot.gif" />end语句能够将多个Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语句组合成一个语句块，并将它们视为一个单元处理。在条件语句和循环等控制流程语句中，当符合特定条件便要执行两个或者多个语句时，就需要使用begin<img src="http://www.cnitblog.com/images/dot.gif" />end语句，其语法形式为：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />{sql_statement</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">statement_block}<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">use</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@message</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">200</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">exists</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> 员工数据表<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> 所属部门</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">办工室</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@message</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">下列人员在办公室工作</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">print</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@message</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> 员工姓名 </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> 员工数据表<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> 所属部门</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">办公室</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@message</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">没有人在办公室</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">print</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@message</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).</span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">
						<img src="http://www.cnitblog.com/images/dot.gif" />else语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">
						<img src="http://www.cnitblog.com/images/dot.gif" />else语句是条件判断语句，其中，else子句是可先的，最简单的if语句没有else子句部分。</span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">
						<img src="http://www.cnitblog.com/images/dot.gif" />else语句用来判断当某一条件成立时执行某段程序，条件不成立时执行另一段程序。SQL Server允许嵌套使用if<img src="http://www.cnitblog.com/images/dot.gif" />else语句，而且嵌套层数没有限制。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> boolean_expression<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> {sql_statement</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">statement_block}<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">else <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> {sql_statement|statement_block}</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).</span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">
						<img src="http://www.cnitblog.com/images/dot.gif" />
				</span>
				<span style="COLOR: #808080">exists</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.if后面的布尔表达式可含有select语句，如果select语句一个值，它可用来与另一值进行比较，以得到布尔表达式。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.如果select语句返回不止一个值，可使用if </span>
				<span style="COLOR: #808080">exists</span>
				<span style="COLOR: #000000">.语法如下：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">exists</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> statement)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> {sql_statement</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">statement_block}<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">else [bolean_expression</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> {sql_statement</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">statement_block}]<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：查询标识号为1389的出版商出版的任何书的信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">exists</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> titles<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> pub_id</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">1389</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">print</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">包含如下图书</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> titles<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> pub_id</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">1389</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">print</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">无</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意：一定不要把if<img src="http://www.cnitblog.com/images/dot.gif" />exists和聚合函数一起使用，因为聚合函数总是返回数据，即使数据是0<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">).while语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />while语句用于设置重复执行SQL语句或语句块的条件。只要指定的条件为真，就重复执行语句。其中，continue语句可以使程序跳过continue语句后面的语句，回到while循环的第一行命令。break语句则使程序完全跳出循环，结束while语句的执行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">break语句交在某些情况发生时，立即无条件地退出最内层while循环，语法为：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />while逻辑表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<img src="http://www.cnitblog.com/images/dot.gif" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">break</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<img src="http://www.cnitblog.com/images/dot.gif" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">continue语句在某些情况发生时，控制程序跳出本次循环，重新天始下一次while循环。语法为：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />while逻辑表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<img src="http://www.cnitblog.com/images/dot.gif" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">continue</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<img src="http://www.cnitblog.com/images/dot.gif" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意：如果select语句用作while语句的条件，那么，select语句必须包含在英文括号中。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@x</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #008000">@y</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #008000">@c</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@x</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #008000">@y</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@x</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">print</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@x</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">while</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@y</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@c</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">100</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #008000">@x</span>
				<span style="COLOR: #808080">+</span>
				<span style="COLOR: #008000">@y</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #0000ff">print</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@c</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@y</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #008000">@y</span>
				<span style="COLOR: #808080">+</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@x</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #008000">@x</span>
				<span style="COLOR: #808080">+</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> </span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@y</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">).case表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />case表达式可以计算多个条件，并将其中一个符合条件的结果表达式返回。case表达式的语法为：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">case</span>
				<span style="COLOR: #000000"> 字段名或变量名<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">when</span>
				<span style="COLOR: #000000"> 逻辑表达式1 </span>
				<span style="COLOR: #0000ff">then</span>
				<span style="COLOR: #000000"> 结果表达式1<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">when</span>
				<span style="COLOR: #000000"> 逻辑表达式2 </span>
				<span style="COLOR: #0000ff">then</span>
				<span style="COLOR: #000000"> 结果表达式2<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">when</span>
				<span style="COLOR: #000000"> 逻辑表达式3 </span>
				<span style="COLOR: #0000ff">then</span>
				<span style="COLOR: #000000"> 结果表达式3<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><img src="http://www.cnitblog.com/images/dot.gif" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000"> 结果表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：调整员工工资，工作级别为1的上调8</span>
				<span style="COLOR: #808080">%</span>
				<span style="COLOR: #000000">，工作级别为2的上调7</span>
				<span style="COLOR: #808080">%</span>
				<span style="COLOR: #000000">，工作级别为3的上调6</span>
				<span style="COLOR: #808080">%</span>
				<span style="COLOR: #000000">，其它上调5</span>
				<span style="COLOR: #808080">%</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">use</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> employee<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> wage</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff00ff">case</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">when</span>
				<span style="COLOR: #000000"> job_level</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">1</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">then</span>
				<span style="COLOR: #000000"> wage</span>
				<span style="COLOR: #808080">*</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1.08</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">when</span>
				<span style="COLOR: #000000"> job_level</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">2</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">then</span>
				<span style="COLOR: #000000"> wage</span>
				<span style="COLOR: #808080">*</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1.07</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">when</span>
				<span style="COLOR: #000000"> job_level</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">3</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">then</span>
				<span style="COLOR: #000000"> wage</span>
				<span style="COLOR: #808080">*</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1.06</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">then</span>
				<span style="COLOR: #000000"> wage</span>
				<span style="COLOR: #808080">*</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1.05</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #000000">).return语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />return语句用于无条件地终止一个查询、存储过程或者批处理，此时位于return之后的程序将不会被执行。return语句的语法形式为：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> 整数表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />通常，存储过程使用返回代码表示存储过程执行的成功或失败。无错误，则返回0，否则，返回非零值。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
				<span style="COLOR: #000000">).waitfor语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />waitfor语句用于暂时停止执行SQL语句、语句块或者存储过程等，直到所设定的时间已过或者所设定的时间已到才继续执行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">waitfor</span>
				<span style="COLOR: #000000"> delay 时间间隔<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中：时间间隔指定执行waitfor语句之前需要等待事件，最多为24小时。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />也可写成：</span>
				<span style="COLOR: #0000ff">waitfor</span>
				<span style="COLOR: #000000"> time 时间值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中，时间值指定waitfor语句将要执行的时间</span>
		</div><img src ="http://www.cnitblog.com/taihang/aggbug/12638.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-21 17:14 <a href="http://www.cnitblog.com/taihang/archive/2006/06/21/12638.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-程序设计基础-自定义函数 </title><link>http://www.cnitblog.com/taihang/archive/2006/06/20/12583.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Tue, 20 Jun 2006 12:57:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/20/12583.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12583.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/20/12583.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12583.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12583.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">东西越来越多！好好学才是硬道理！<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />用户自定义函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />自定义函数不能执行一系列改变数据库状态的操作，可以像系统函数在查询或存储过程等的程序中使用，也可以像相信过程一样能过execute命令来执行。自定义函数中存储了一个Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL例程可以返回一定的值。根据函数返回值形式的不同，将用户看定义函数分为三种类型：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).标量型函数：标量型函数返回一个确定类型的标量值，其返回值类型为除了text,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">ntext</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">image</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">,timestampt和table类型外的其它数据类型。函数体语句定义在begin</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">end语句内，其中包含了可以返回值的Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL命令。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">owner_name</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> function_name <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">{@parameter_name [as</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> scalar_parameter_data_type</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">=default</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">} </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">])<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">returns</span>
				<span style="COLOR: #000000"> scalar_return_data_type<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">with &lt;function_option&gt; [,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">]<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">as</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />function_body<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">scalar_expression</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.function_option有两个可选值：{encryption</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">schemabinding}<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />encryption:加密选项，让SQL Server对系统表中有关create function的声明加密，以防止用户自定义函数作为SQL Server复制的一部分被发布。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />schemabinding，计划绑定选项。将用户自定义函数绑定到它所引用的数据库对象，则函数所涉及的的数据库对象从此将不能被删除或修改，除非函数被删除或去掉此选项。应注意的是要绑定的数据库对象必须与函数在同一数据库中。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.owner_name:指定用户自定义函数的所有者。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.function_name:指定用户自定义函数的名称。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.database_name.owner_name.function_name应是唯一的。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #008000">@parameter_name</span>
				<span style="COLOR: #000000">:定义一个式多个参数的名称，一个函数最多可以定义1024个参数，每个参数前用</span>
				<span style="COLOR: #008000">@符号标明</span>
				<span style="COLOR: #000000">，参数的作用范围是整个函数，参数只能替代常量，不能替代表名，列名或其它数据库对象名称，用户自定义函数不支持输出参数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.scalar_parameter_data_type:指定标量参数的数据类型，除了text,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">ntext</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">image</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">,timestampt和table类型外的其它数据类型。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.scalar_return_data_type:指定标量返回值的数据类型，除了text,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">ntext</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">image</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">cursor</span>
				<span style="COLOR: #000000">,timestampt和table类型外的其它数据类型。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">8</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.scalar_expression:指定标量型用户自定义函数返回的标量值表达式。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">9</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.function_body:指定一系列的Transact_SQL语句它们决定了函数的返回值。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：创建军工龄工资计算函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">use</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008080">--</span>
				<span style="COLOR: #008080">创建函数</span>
				<span style="COLOR: #008080">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000"> workyearwage(</span>
				<span style="COLOR: #008000">@hiredate</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">datetime</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #008000">@today</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">datetime</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #008000">@per_wage</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">money</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008080">--</span>
				<span style="COLOR: #008080">hiredate表示雇佣期,today表示当前日期，par_wage表示每一年的工龄应得的工资额</span>
				<span style="COLOR: #008080">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">returns</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">money</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@workyearwage</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">money</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@workyearwage</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">year</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #008000">@today</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #ff00ff">year</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #008000">@hiredate</span>
				<span style="COLOR: #000000">))</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #008000">@per_wage</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #008000">@workyearwage</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #008080">--</span>
				<span style="COLOR: #008080">结束函数定义</span>
				<span style="COLOR: #008080">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008080">--</span>
				<span style="COLOR: #008080">调用函数</span>
				<span style="COLOR: #008080">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> taihang.dbo.workyearwage(</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">1999-7-1</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">getdate</span>
				<span style="COLOR: #000000">(),</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">15</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> work_year_wage<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意：以上的函数体可简写为:<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">((</span>
				<span style="COLOR: #ff00ff">year</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #008000">@today</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #ff00ff">year</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #008000">@hiredate</span>
				<span style="COLOR: #000000">))</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #008000">@per_wage</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).内嵌表值函数：以表的形式返回一个返回值，即它返回的是一个表。内嵌表值型函数没有由begin</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">end语句括起来的函数体，其返回的表由一个位于return子句中的select命令段从数据库中筛先出来。内嵌表值型函数功能相当于一个参数化的视图。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />创建函数语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">owner_name</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> function_name <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">{@parameter_name [as</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> scalar_parameter_data_type</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">=default</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">} </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">])<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">returns</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">with &lt;function_option&gt; [,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">]<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">as</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">stmt)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000">:批定返回值为一个表。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">stmt:单个select语句，确定返回的表的数据。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：创建返回所有订购某类产品的公司信息函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">use</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000"> orderfirms(</span>
				<span style="COLOR: #008000">@productid</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">30</span>
				<span style="COLOR: #000000">))<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008080">--</span>
				<span style="COLOR: #008080">productid表示产品代号</span>
				<span style="COLOR: #008080">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">returns</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> products p <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />       </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> p.p_id</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #008000">@productid</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).多语句表值型函数：可以看作标量型和内嵌表值型函数的结合体，它的返回值是一个表，但它和标量型函数一样有一个用begin</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">end语句括起来的函数体。返回值表中的数据是由函数体<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">owner_name</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> function_name <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">{@parameter_name [as</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> scalar_parameter_data_type</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">=default</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">} </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">])<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">returns</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@return_variable</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">table_type_definition</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">with &lt;function_option&gt; [,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">]<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">as</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">begin</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />function_body<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">end</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">table_type_definition</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">:({column_definition</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">table_constraint}</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #008000">@return_variable</span>
				<span style="COLOR: #000000">:一个table类型的变量，用于存储和累积返回的表中的数据行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.修改用户自定义函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">alter</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000">:此命令语法与create function相同，相当于重建。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">.删除用户自定义函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">drop</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000">{</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">owner_name</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">function_name} </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />建议到企业管理器里修改，简单、方便。</span>
		</div><img src ="http://www.cnitblog.com/taihang/aggbug/12583.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-20 20:57 <a href="http://www.cnitblog.com/taihang/archive/2006/06/20/12583.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-程序设计基础-函数</title><link>http://www.cnitblog.com/taihang/archive/2006/06/20/12560.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Tue, 20 Jun 2006 07:31:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/20/12560.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12560.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/20/12560.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12560.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12560.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">慢慢学，心急不行！<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />五、函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />在Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语言中，函数被用来执行一些特殊的运算以支持SQL Server的标准命令。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).行集函数：行集函数可以在transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语句中当作表引用。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).聚合函数：用于一组值执行计算并返回一个单一的值。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).标量函数：用于对传递给它的一个或者多个参数值进行处理和计算，并返回一个单一的值.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(一)、标量函数的分类<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.配置函数：返回当前的配置信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.游标函数：返回有关游标的信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.日期和时间函数：用于对日期和时间类型的输入值进行操作，返回一个了子符串，数字或日期和时间值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.数学函数：用于对作为函数参数提供的输入值执行操作，返回一个数字值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">.元数据函数：返回有关数据库和对象和信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #000000">.字符串函数：对字符串输入值执行操作，并返回一个字中或数字值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
				<span style="COLOR: #000000">.系统函数：执行系统操作<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">8</span>
				<span style="COLOR: #000000">.系统统计函数：返回系统的统计信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">9</span>
				<span style="COLOR: #000000">.文本和图像函数：对于文本或图像输入值或列执行操作，返回有关这些值的信息。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />具体讲解：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.系统函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />用于返回有关SQL Server系统，用户，数据库和数据库对象的信息。系统函数可以让用户在得到信息后，使用条件语句，根据返回的信息进行不同的操作。与其它函数一样，可以在select语句的select和where子句经及表达式中使用系统函数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：返回taihang数据库的yuan表中的第二列的名称。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">use</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">col_name</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">object_id</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">yuan</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">),</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：col_name为系统函数，</span>
				<span style="COLOR: #ff00ff">object_id</span>
				<span style="COLOR: #000000">:返回对象的id。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.日期和时间类型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />日期和时间函数用于对日期和时间数据进行各种不同的处理和运算，并返回一个字符串，数字值或日期和时间值。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">dateadd</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">datepart</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">number</span>
				<span style="COLOR: #000000">,date)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">datediff</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">datepart</span>
				<span style="COLOR: #000000">,date1,date2)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">datename</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">datepart</span>
				<span style="COLOR: #000000">,date)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">datepart</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">datepart</span>
				<span style="COLOR: #000000">,date)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">day</span>
				<span style="COLOR: #000000">(date)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">getdate</span>
				<span style="COLOR: #000000">()<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">month</span>
				<span style="COLOR: #000000">(date)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">year</span>
				<span style="COLOR: #000000">(date)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：从getdate函数返回的日期中提取月份数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">datepart</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff00ff">month</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">getdate</span>
				<span style="COLOR: #000000">()) </span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">month number</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注:datepart为系统函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2：从03</span>
				<span style="COLOR: #808080">/</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">12</span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #000000">1998中返回月份、天数和年份数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">month</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">03/12/1998</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #ff00ff">day</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">03/12/1998</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #ff00ff">year</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">03/12/1998</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.、字符串函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />可对二进制数据、字符串和表达式执行不同的运算，大多数字符串函数只能用于char和varchar数据类型以及明确转换成char和varchar的数据类型，少数几个字符串函数也可以用binary和varbinary数据类型。此外，果些字符串还可以处理text,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">ntext</span>
				<span style="COLOR: #000000">,image数据类型的数据。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.字符串函数的分类：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).基本字符串函数：</span>
				<span style="COLOR: #ff00ff">upper</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">lower</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">space</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">replicate</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">stuff</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">reverse</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">ltrim</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">rtrim</span>
				<span style="COLOR: #000000">.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).字符串查找函数：</span>
				<span style="COLOR: #ff00ff">charindex</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">patindex</span>
				<span style="COLOR: #000000">.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).长度和分析函数：</span>
				<span style="COLOR: #ff00ff">datalength</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">substring</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">right</span>
				<span style="COLOR: #000000">.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">).转换函数：asch,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">char</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">str</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">soundex</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff00ff">difference</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.数学函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />用于对数字表达式进行数学运算并返回运算结果。数学函数可以对SQL Server提供的数字数据(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">decimal</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">integer</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">float</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">real</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">money</span>
				<span style="COLOR: #000000">,samllmoney,smallint和tinyint)进行处理。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：在一表达式中使用ceiling(向上取整),</span>
				<span style="COLOR: #ff00ff">floor</span>
				<span style="COLOR: #000000">(向下到整),</span>
				<span style="COLOR: #ff00ff">round</span>
				<span style="COLOR: #000000">(四舍五入，N位小数)函数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">ceiling</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">13.4</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #ff00ff">floor</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">13.4</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #ff00ff">round</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">13.4567</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />结果为14，</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">13</span>
				<span style="COLOR: #000000">，</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">13.4570</span>
				<span style="COLOR: #000000">。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">.转换函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />一般情况下，SQL Server会自动处理某些数据类型的转换。例如，如果比较char和datetime表达式、smallint和int表达式、或不同长度的char表达式，SQL Serve可以将它们自动转换，这种自动转换称为隐性转换。但是无法由SQL Serve自动转换的或者是SQL Serve自动转换的结果不符合预期结果的，就需要使用转换函数做显示转换。转换函数有两个：convert和cast.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).</span>
				<span style="COLOR: #ff00ff">cast</span>
				<span style="COLOR: #000000">(expression </span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> data_type)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).couvert函数允许用户反表达式从一钟数据类型转换成另一钟数据类型，还允许反日期转换成不同的样式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">convert</span>
				<span style="COLOR: #000000"> (data_type</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">length</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">,expression</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,style</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">use</span>
				<span style="COLOR: #000000"> bubs<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> title,ytd_sales </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> titles<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">cast</span>
				<span style="COLOR: #000000">(ytd_sales </span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">char</span>
				<span style="COLOR: #000000">(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">20</span>
				<span style="COLOR: #000000">)) </span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">15%</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />     </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000"> type</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">trad_cook</span>
				<span style="COLOR: #ff0000">'</span>
		</div><img src ="http://www.cnitblog.com/taihang/aggbug/12560.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-20 15:31 <a href="http://www.cnitblog.com/taihang/archive/2006/06/20/12560.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-程序设计基础-运算符</title><link>http://www.cnitblog.com/taihang/archive/2006/06/17/12425.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Sat, 17 Jun 2006 09:25:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/17/12425.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12425.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/17/12425.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12425.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12425.html</trackback:ping><description><![CDATA[<p>
				<img height="19" src="http://www.cnitblog.com/Emoticons/car.gif" width="19" border="0" />
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">运算符还这么多讲究，晕死了！<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />不过网络笔记做起来感觉还不错，等做完了，到时到个网站发表一下也不错，名子叫做&lt;太行学习笔记&gt;！<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />运算符是一些符号，它们能够用来执行算术运算、字符串连接、赋值以及在字段常量和变量之间进行比较。在SQL Server 2000中，运算符主要有以下六大类：算术运算符、赋值运算符、位运算符、逻辑运算符以及字符串串联接运算符。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.算术运算符：可在两个表达式上执行数学运算，两个表达式可以是数字数据类型分类的任何数据类型。包括：</span>
				<span style="COLOR: #808080">+</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #000000">和取模(</span>
				<span style="COLOR: #808080">%</span>
				<span style="COLOR: #000000">)。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.赋值运算符：Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL中的运算符(</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">),(</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">)还可以在列标题和为列定义值的表达式之间建立关系。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.位运算符：在整形数据或者二进制数据(image类型除外)之间执行位操作。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />运算符</span>
				<span style="COLOR: #808080">&amp;</span>
				<span style="COLOR: #000000">(按位AND),</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">(按位OR),</span>
				<span style="COLOR: #808080">^</span>
				<span style="COLOR: #000000">(按位异或XOR)都是两上操作数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.比较运算符：比较两个表达式的大小或是否相同，其比较的结果是布尔值，即：true(表达式结果为真)、false、以及unknown。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">text</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">ntext</span>
				<span style="COLOR: #000000">,image数据类型不可用。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">.逻辑运算符：可把多个逻辑表达式连接起来。包括AND，OR和NOT等运算符，返回带有true,false值和布尔数据类型。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #000000">.字符串串联运算符：用</span>
				<span style="COLOR: #808080">+</span>
				<span style="COLOR: #000000">加号进行字符串串联，例：语句select </span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">tai</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #808080">+</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">hang</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,其结果为taihang。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />运算符的优先级从高到低排列：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.括号：( )<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.乘、除、求模运算符：</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">、</span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #000000">、</span>
				<span style="COLOR: #808080">%</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.加减运算符：</span>
				<span style="COLOR: #808080">+</span>
				<span style="COLOR: #000000">、</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.比较运算符：</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&gt;=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;&gt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">!=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">!&gt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">!&lt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">.位运算符：</span>
				<span style="COLOR: #808080">^</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&amp;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #000000">.逻辑运算符：</span>
				<span style="COLOR: #808080">NOT</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
				<span style="COLOR: #000000">.逻辑运算符：</span>
				<span style="COLOR: #808080">AND</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">8</span>
				<span style="COLOR: #000000">.逻辑运算符：</span>
				<span style="COLOR: #808080">OR</span>
		</div><img src ="http://www.cnitblog.com/taihang/aggbug/12425.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-17 17:25 <a href="http://www.cnitblog.com/taihang/archive/2006/06/17/12425.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-程序设计基础-注释、变量</title><link>http://www.cnitblog.com/taihang/archive/2006/06/17/12420.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Sat, 17 Jun 2006 06:56:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/17/12420.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12420.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/17/12420.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12420.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12420.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">这么多，慢慢学！成功真是不易呀！<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />二、注释<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.代码中不执行的文本字符串，也称为注解。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.SQL server中有两种类型的注释字符：一种是ANSI标准的注释符‘</span>
				<span style="COLOR: #008080">--</span>
				<span style="COLOR: #008080">’,另一种是与C语言相同的程序注释符号，即“/* */”</span>
				<span style="COLOR: #008080">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">例如：(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).</span>
				<span style="COLOR: #008080">--</span>
				<span style="COLOR: #008080">检索部门的员工。(2)./*检索部门的员工*/。</span>
				<span style="COLOR: #008080">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />三、变量<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />变量是一种语言中必不可少的组成部分。Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语言中有两种形式的变量，一种是用户自己定义的局部变量，另一种是系统提供的全局变量。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.全局变量是SQL Server系统内部的变量其作用范围并不仅仅局限于某一程序。而是任何程序均可以随时调用，全局变量通常存储一些SQL Server的配置设定值和统计数据。用户可以在程序中用全局变量来测试系统的设定值或者是Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL命令执行后的状态值。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).全局变量不是由用户的程序定义的，它们是在服务器级定义的。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).用户只能使用预先定义的全局变量。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).引用全局变量时，必须以标记符“@@”开头。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">).局部变量的名称不能与全局变量的名称相同，否刚会在应用程序中出现不可预测的结果。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：</span>
				<span style="FONT-WEIGHT: bold; COLOR: #008000">@@error全局变量将返回最后执行的T</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语句的错误代码，数据类型为整型，在SQL server执行一个T</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语句之后，若成功。则返回值为0；否则相应的错误代码。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.局部变量是一个能够拥有特定数据类型的对象，它的作用范围仅限制在程序内部。局部变量可以作为计数器来计算循环执行的次数，或是控制循环执行的次数。另外，利用局部变量还可以保存数据值，以供控制流语句测试以及保存由存储过程返回的数据值等。局部变量被引用时要在其名称前加上标志“@”，而且必须先用declare命令定义后才可以使用。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).声明局部变量：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />格式：</span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@变量名</span>
				<span style="COLOR: #000000">　变量类型 </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,@变量名　变量类型<img src="http://www.cnitblog.com/images/dot.gif" /></span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其中：变量类型可以是SQL server2000支持所有系统数据类型，也可以是用户自定义的数据类型。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).局部变量赋值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />在Transact</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL中，不能像在一般的程序语言中一样使用变量＝变量值来给变量赋值，必须使用select或set命令来设定变量的值，其语法如下：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@局部变量</span>
				<span style="COLOR: #000000">＝变量值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />或set </span>
				<span style="COLOR: #008000">@局部变量</span>
				<span style="COLOR: #000000">＝变量值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：声明一个长度为10个字符的变量id并赋值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@id</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">10</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@id</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">007</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">declare</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@max_salary</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #008000">@max_salary</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff00ff">max</span>
				<span style="COLOR: #000000">(工资)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> 员工数据表<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意:局部变量的作用范围是从声明该局部变量的地方开如，到声明局部变量的批处理或存储过程的结尾。在局部变量的作用范围以外引用该局部变量将产生语法错误。</span>
		</div><img src ="http://www.cnitblog.com/taihang/aggbug/12420.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-17 14:56 <a href="http://www.cnitblog.com/taihang/archive/2006/06/17/12420.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-程序设计基础-批处理</title><link>http://www.cnitblog.com/taihang/archive/2006/06/17/12413.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Sat, 17 Jun 2006 02:39:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/17/12413.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12413.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/17/12413.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12413.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12413.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">作这个笔记，比写在纸上好多了！！！<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />其它语言元素<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />一、批处理<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.批处理：指包含一条或多条T</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语句的语句组，这组语句从应用程序一次性地发送到SQL server服务器执行。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.执行单元：SQL server服务器将批处理语句编译成一个可执行单元，这种单元称为执行单元。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.若批处理中的某条语句编译出错，则无法执行。若运行出错，则视情况而定。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.书写批处理时,go语句作为批处理命令的结束标志，当编译器读取到go语句时，会把go语句前的所有语句当作一个批处理，并将这些语句打包发送给服务器。go语句本身不是T</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">SQL语句的的组成部分，只是一个表示批处理结束的前端指令。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">.建立批处理里注意：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).</span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">default</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">rule</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">create</span>
				<span style="COLOR: #000000"> trigger和create view等语句在同一个批处理中只能提交一个。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).不能在删除一个对象之后，在同一批处理中再次引用这个对象。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">).不能把规则和默认值绑定到表字段或者自定义字段上之后，立即在同一批处理中使用它们。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">).不能定义一个check约束之后，立即在同一个批处理中使用。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">).不能修改表中一个字段名之后，立即在同一个批处理中引用这个新字段。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #000000">).使用set语句设置的某些set选项不能应用于同一个批处理中的查询<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
				<span style="COLOR: #000000">).若批处理中第一个语句是执行某个存储过程的execute语句，则execute关键字可以省略。若该语句不是第一个语句，则必须写上。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">use</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> yuan<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />creacte </span>
				<span style="COLOR: #0000ff">view</span>
				<span style="COLOR: #000000"> view1 </span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> yuan<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> qq</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">
						<a title="asdf" href="asdf">asdf</a>
				</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> view1<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">go</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div><img src ="http://www.cnitblog.com/taihang/aggbug/12413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-17 10:39 <a href="http://www.cnitblog.com/taihang/archive/2006/06/17/12413.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-SQL server自定义数据类型 </title><link>http://www.cnitblog.com/taihang/archive/2006/06/15/12299.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Thu, 15 Jun 2006 07:25:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/15/12299.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12299.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/15/12299.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12299.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12299.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">自定义数据类型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />建立在SQL server系统数据类型基础上的，需要指定该类型的名称，建立在其上的系统数据类型及是否充许为空。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />方法：利用系统存储过程：sp_addtype<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：sp_addtype type,</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">system_data_type</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,'nulltype'</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.type是用户定义数据类型的名称。数据类型名称必须遵循标识符规则，并且在每个数据库中必须是唯一的。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.system_data_type是SQL server提供的数据类型，用户定义的数据类型即基于该类型。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">nulltype</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">:指定必须如何处理null值。设置null默认，</span>
				<span style="COLOR: #808080">not</span>
				<span style="COLOR: #000000"> null或nonull<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：自定义数据类型taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">exec</span>
				<span style="COLOR: #000000"> sp_addtype taihang,smllint,</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">not null</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2：删除自定义数据类型taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">exec</span>
				<span style="COLOR: #000000"> sp_droptype taihang</span>
		</div>
<img src ="http://www.cnitblog.com/taihang/aggbug/12299.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-15 15:25 <a href="http://www.cnitblog.com/taihang/archive/2006/06/15/12299.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>T-SQL学习笔记-SQL server数据类型</title><link>http://www.cnitblog.com/taihang/archive/2006/06/15/12298.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Thu, 15 Jun 2006 07:23:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/15/12298.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12298.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/15/12298.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12298.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12298.html</trackback:ping><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">sql server数据类型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.数据类型指定列、存储过程参数及局部变量的数据特性<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.数据按照数据类型存储在列中<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />　(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">).系统数据类型：SQL server支持的内置数据类型。有25种。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />　(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">).用户定义的数据类型：用户根据系统数据类型自己定义的数据类型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />数据类型:<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />一、字符型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">char</span>
				<span style="COLOR: #000000">(n):n字节，非unicode字符数据，输入字符少于N，以空格填满，长则截掉<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />，N为1</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">8000范围。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
				<span style="COLOR: #000000">(n):实际长度，节省空间，其它同上。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">nchar</span>
				<span style="COLOR: #000000">(n):n单位，unicode标准，两个字节为存储单位，n为1</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">4000范围。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">nvarchar</span>
				<span style="COLOR: #000000">(n):实际长度，节省空间，其它同上。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />二、整型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
				<span style="COLOR: #000000">:存储长度为4个字节，范围负的2的31次方至2的31次方减1内所有整数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">smallint</span>
				<span style="COLOR: #000000">:存储长度为2个字节，范围负的2的15次方至2的31次方减1内所有整数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">tinyint</span>
				<span style="COLOR: #000000">:存储长度为1个字节，范围0</span>
				<span style="COLOR: #808080">-</span>
				<span style="COLOR: #000000">255内所有整数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：identity属性只适用于以上三种。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />三、浮点型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">real</span>
				<span style="COLOR: #000000">:存储长度为4个字节，范围精确到7位小数。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">float</span>
				<span style="COLOR: #000000">:存储长度为8个字节，最多可精确到15位小数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">decimal</span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #000000">numeric:实际存储空间，</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">decimal</span>
				<span style="COLOR: #000000">(p,s),p表示总位数,s表示小数点后的位数。</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">0</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="COLOR: #000000">s</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="COLOR: #000000">p</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">38</span>
				<span style="COLOR: #000000">。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：以上存储十进制小数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />四、货币型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">money</span>
				<span style="COLOR: #000000">:8个字节，用于存储货币，精确度为万分之一。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">smallmoney</span>
				<span style="COLOR: #000000">:4个字节，范围比money小，精确度为万分之一。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />五、位型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">bit</span>
				<span style="COLOR: #000000">:1个字节，逻辑变量表示真假，只输入0与1<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />六、日期与时间型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">datetime</span>
				<span style="COLOR: #000000">:8个字节精度三百分之一秒，即3.33毫秒。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />适用范围：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />MM DD YYYY hh:mmm AM</span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #000000">PM<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1753.1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">-</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">9999.12</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">31</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">23</span>
				<span style="COLOR: #000000">:</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">59</span>
				<span style="COLOR: #000000">:</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">59</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.smlldatetime:4个字节，精度1分钟。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />适用范围：</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1900.1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">-</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2079.6</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：以上两种为存储日期和时间的结合体，引用时用单引号。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />七、二进制型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">binary</span>
				<span style="COLOR: #000000">(n):n为长度，范围是固定长度的二进制数据，n为1－</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">8000</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">varbinary</span>
				<span style="COLOR: #000000">(n):长度为N</span>
				<span style="COLOR: #808080">+</span>
				<span style="COLOR: #000000">4字节,范围是二进制数据的长度未升或变化较大时可用，存放8000节字节内可变长数据<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />八、文本型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">text</span>
				<span style="COLOR: #000000">:存储长度为实际大小，最大可存储2的31次方减1，存储长度大于8000个字节的二进制数据。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">ntext</span>
				<span style="COLOR: #000000">:存储长度为实际大小，最大可存储2的30次方减1，存储长度大于4000个字符的unicode字符串。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />九、图形型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">image</span>
				<span style="COLOR: #000000">:存储长度为实际大小，最大可存储2的31次方照片，存储长度大于8000个字符的字符串。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />十、特殊型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">timestamp</span>
				<span style="COLOR: #000000">:存储长度为8个字节，提供数据库范围内的唯一值，单调上升的计数器。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">uniqueidentifier</span>
				<span style="COLOR: #000000">:存储长度为16个字节，存储一个16字节长的二进制数，全局惟一标识符，<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：全局惟一标识符(GUID),由计算机见外网卡和CPU时种产生的，每台机器不会重复。</span>
				<span style="COLOR: #ff00ff">newid</span>
				<span style="COLOR: #000000">()函数可求出。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />十一、新增型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">bigint</span>
				<span style="COLOR: #000000">:存储长度为8个字节,适用范围负的2的63次方至2的63次方减1。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.sql_variant:存储除文本，图形数据和timestamp类型数据外的其它任何合法的<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />SQL server数据。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #0000ff">table</span>
				<span style="COLOR: #000000">:用于存储对表或视图处理后的结果集，可存储一个表。<br />   </span>
		</div>
<img src ="http://www.cnitblog.com/taihang/aggbug/12298.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-15 15:23 <a href="http://www.cnitblog.com/taihang/archive/2006/06/15/12298.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记－数据的插入、更新和删除</title><link>http://www.cnitblog.com/taihang/archive/2006/06/14/12226.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Wed, 14 Jun 2006 02:36:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/14/12226.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12226.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/14/12226.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12226.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12226.html</trackback:ping><description><![CDATA[
		<img height="20" src="http://www.cnitblog.com/Emoticons/QQ/24.gif" width="20" border="0" />
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">数据插入<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />格式1：</span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">表名</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">列名1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">　</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,&lt;列名2&gt;<img src="http://www.cnitblog.com/images/dot.gif" /></span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">) </span>
				<span style="COLOR: #0000ff">values</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">值1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,&lt;值2&gt;<img src="http://www.cnitblog.com/images/dot.gif" /></span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />insert语句把values后给出的各值按排列顺序依次赋到表名后列出的各列，每次只能在一列中插入一条记录,没有值的列为：</span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：</span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> taihang <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />     </span>
				<span style="COLOR: #0000ff">values</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">007</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">男</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">太行</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2：</span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> taihang(id,sex,name) <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />     value (</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">007</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">男</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">太行</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />格式2：</span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">表名</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">列名1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">　</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,&lt;列名2&gt;<img src="http://www.cnitblog.com/images/dot.gif" /></span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">) select语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.把select语句查询结果按顺序插入到对应的列中，允许一次插入多条记录。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.select查询的条列值必须与</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">表名</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">后的各列名在个数、类型及顺序上一致。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.若</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">表名</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">后没有(列名)，则对该表的所有字段插入<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：</span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> taihang1(id1,sex1,name1)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />　　</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> id,sex,name </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />数据修改<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />格式：</span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">表名</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">列名1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">＝</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">表达式1</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,&lt;列名2&gt;=&lt;表达式2&gt;<img src="http://www.cnitblog.com/images/dot.gif" /></span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">where&lt;条件&gt;</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.该语句在指定表中符合where</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">条件</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">的行中指定列赋新值，如没有where，则对整表修改。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：将学生taihang转入computert系<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> student<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> dept</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">computer</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> name</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">taihang</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2: 所有学生年龄加1<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">update</span>
				<span style="COLOR: #000000"> student<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> age</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">age</span>
				<span style="COLOR: #808080">+</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />删除数据<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />格式：</span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">from</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> {table_name</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #000000">view_name} </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">where子句</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.删除表中符合条件的行，delete只能删除整行，不能删除一行的部分，若无where部<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />分，则成空表，只留表结构。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：删除学号为007的学生信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> no</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">007</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2：删除没有成绩的学生信息<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> grade </span>
				<span style="COLOR: #0000ff">is</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.数据更新语句只能对单表打操作，不能同时对多表更新。(从而引起阶段性的数据不一致)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.数据更新语句仅当事务(</span>
				<span style="COLOR: #0000ff">transaction</span>
				<span style="COLOR: #000000">)提交(</span>
				<span style="COLOR: #0000ff">commit</span>
				<span style="COLOR: #000000">)后才正式生效。也可通过事务回滚(</span>
				<span style="COLOR: #0000ff">rollback</span>
				<span style="COLOR: #000000">)来作废。这回的还简单些。</span>
		</div>
<img src ="http://www.cnitblog.com/taihang/aggbug/12226.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-14 10:36 <a href="http://www.cnitblog.com/taihang/archive/2006/06/14/12226.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记－如何提高select语句的效率</title><link>http://www.cnitblog.com/taihang/archive/2006/06/13/12148.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Tue, 13 Jun 2006 02:27:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/13/12148.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12148.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/13/12148.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12148.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12148.html</trackback:ping><description><![CDATA[1.使用exists关键字检查结果集：不要用count(*)来检查结果集中是否包含行。<br />2.使用标准联接代替嵌套查询：在执行嵌套查询时，SQL server将先执行内部的子查询，然后将查询结果返回给外部查询的作为检索的数据源，最后执行外部的主查询。而在执行包含标准联接的查询时，SQL server将要执行的仅仅是一个查询。<br />3.有效避免整表扫描，使用索引。<br />4.在like子句的匹配条件的开始使用了%，若在like子句的匹配条件的开始使用了%，那么包含这个like分句的查询将会调用整表扫描。<br />5.以上四点说的还挺有道理。<img src ="http://www.cnitblog.com/taihang/aggbug/12148.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-13 10:27 <a href="http://www.cnitblog.com/taihang/archive/2006/06/13/12148.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记－嵌套查询</title><link>http://www.cnitblog.com/taihang/archive/2006/06/12/12100.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Mon, 12 Jun 2006 05:51:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/12/12100.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/12100.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/12/12100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/12100.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/12100.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">嵌套查询<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />定义：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.指在一个外层查询中包含有另一个内层查询。其中外层查询称为主查询，内层查询称为子查询。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.SQL允许多层嵌套，由内而外地进行分析，子查询的结果作为主查询的查询条件<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.子查询中一般不使用order by子句，只能对最终查询结果进行排序<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />子查询(sub query)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> 表达式 </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">not</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000"> (子查询)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> 表达式 比较运算符</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">any|all</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> 子查询<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">not</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">exists</span>
				<span style="COLOR: #000000"> (子查询)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.子查询－单值比较<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />返回单值子查询，只返回一行一列<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />主查询与单值子查询之间用比较运算符进行连接：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />运算符:</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&gt;=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：找出与太行同龄的同事<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> company<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> company<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />             </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> name</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">taihang)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.子查询－</span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：查询选修了‘</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">001</span>
				<span style="COLOR: #000000">’课程的学生学号，姓名。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> id,name<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> id </span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> id <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />             </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />             </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> id</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">001</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.子查询－多值比较all<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />多行一列<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.父查询与多值子查询之间的比较需用all来连接<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.标量值S比子查询返回集R中的每个都大时，s</span>
				<span style="COLOR: #808080">&gt;all</span>
				<span style="COLOR: #000000">,r为true<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.all表示所有<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #808080">&gt;all</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;all</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&gt;=all</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;=all</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;&gt;all</span>
				<span style="COLOR: #000000">,注：all等价于not </span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：找出年龄最小的学生<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> age</span>
				<span style="COLOR: #808080">&lt;all</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.子查询－多值比较some</span>
				<span style="COLOR: #808080">/any</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.父查询与多值子查询之间的比较需用some</span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #000000">any来连接<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.标量值S比子查询返回集r中的某一个都大时，s</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">some时r为true 或s</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">any时r为true<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.some表示部分<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #808080">&gt;some</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&gt;=some</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">=some</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;some</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;=some</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;&gt;some</span>
				<span style="COLOR: #000000">,注：</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">some等价于in,</span>
				<span style="COLOR: #808080">&lt;&gt;</span>
				<span style="COLOR: #000000">some不等价于not </span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000">.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：找出不是最小年龄的学生<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">some</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">.子查询－存在判断exists<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #808080">exists+</span>
				<span style="COLOR: #000000">子查询用来判断该子查询是否返回元组<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.当子查询的结果集非空时，exists为true<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.当子查询的结果集为空时，exists为false<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
				<span style="COLOR: #000000">.不关心子查询的具体内容，因此用select </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：列出先修了C01课程的学习的学号，姓名<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> son,sname<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> strdent<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">exists</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> sc<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />             </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> sc.sno</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">stusent.sno </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />             cno</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">C01</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />最后这一个不是很好理解呀！等用多了就好了。</span>
		</div>
<img src ="http://www.cnitblog.com/taihang/aggbug/12100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-12 13:51 <a href="http://www.cnitblog.com/taihang/archive/2006/06/12/12100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记－联接查询</title><link>http://www.cnitblog.com/taihang/archive/2006/06/09/11893.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Fri, 09 Jun 2006 07:02:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/09/11893.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/11893.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/09/11893.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/11893.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/11893.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">联接查询<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />根据各个数据表之间的逻辑关系从两个或多个数据表中检索数据定义数据表关联方式：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.在数据表中指定用于联接的字段。一个表中指定处键，在别一表中指定与其关联的主键<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.在select语句中指定比较各字段值时要使用逻辑运算符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />联接类型<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.内连接<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />表1 </span>
				<span style="COLOR: #0000ff">inner</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> 表2 </span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 联接表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />指定匹配行，inner为缺省连接方式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> 员工数据表<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">inner</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> 项目数据表<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 员工数据表.员工编号</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">项目数据表.负责人编号<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.外联接：左向外联接，右向外联接，完整外联接<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">)左向外联接：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />table1 </span>
				<span style="COLOR: #ff00ff">left</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> table2 </span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 联接表达式　或<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />table1 </span>
				<span style="COLOR: #ff00ff">left</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">outer</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> table2 </span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 联接表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：返回结果集中包括数据表1中所有数据，不仅仅是联接字段所匹配的记录。如果表1的某条记录在表2中没有匹配的记录，则结果集相应记录有关表2的所有字段为空值。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">)右向个联接与之左正相反<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />table1 </span>
				<span style="COLOR: #ff00ff">right</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> table2 </span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 联接表达式　或<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />table1 </span>
				<span style="COLOR: #ff00ff">right</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">outer</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> table2 </span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 联接表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：与之左正相反<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">)完整外连接<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />table1 </span>
				<span style="COLOR: #0000ff">full</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> table2 </span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 联接表达式　或<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />table1 </span>
				<span style="COLOR: #0000ff">full</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">outer</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> table2 </span>
				<span style="COLOR: #0000ff">on</span>
				<span style="COLOR: #000000"> 联接表达式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：返回结果集中包含表1和表2所有记录，互相没有区配记录时添充空值<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000">.交叉联接<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />table1 </span>
				<span style="COLOR: #0000ff">cross</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">join</span>
				<span style="COLOR: #000000"> table2<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />当没有where子句，将返回表1和表2的笛卡儿乘积，即表1与表2的所有记录的不同交叉组合</span>
		</div>
<img src ="http://www.cnitblog.com/taihang/aggbug/11893.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-09 15:02 <a href="http://www.cnitblog.com/taihang/archive/2006/06/09/11893.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记－union子句用法</title><link>http://www.cnitblog.com/taihang/archive/2006/06/09/11874.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Fri, 09 Jun 2006 03:04:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/09/11874.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/11874.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/09/11874.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/11874.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/11874.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">union子句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />union操作符将两个查询结果合并为一个结果集。为连接查询合并两个表时：列的数日和顺序在查中必须一致；数据类型兼容<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />语法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> 语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">union</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">all</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> 语句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注意：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">.union运算从最终结果集中删除重复记录，如想不删除重复记录使用all关键字<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000">.第一个select语句中不能用order by或compute子句，只能是最后一个select语名后用<br /></span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：查询计算机系的学生式年龄不大于19岁的学习，按年龄倒排序<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> department </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> dept</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">computer</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">union</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">select</span> </span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> student </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> age</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">19</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">order</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #0000ff">desc</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />注：两表中字段一致，<img height="20" src="http://www.cnitblog.com/Emoticons/hitwall.gif" width="25" border="0" />内容太丰富了，头都大了</span>
		</div>
<img src ="http://www.cnitblog.com/taihang/aggbug/11874.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-09 11:04 <a href="http://www.cnitblog.com/taihang/archive/2006/06/09/11874.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记－汇总函数用法</title><link>http://www.cnitblog.com/taihang/archive/2006/06/08/11851.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Thu, 08 Jun 2006 10:21:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/08/11851.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/11851.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/08/11851.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/11851.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/11851.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">汇总函数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />avg平均值，count计数，max最大值，min最小值,sum求和<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />全部忽略null<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">)函数将所有符合条件的记录都计算在内<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：人员总数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例1：各部门中最高工资数额<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> id </span>
				<span style="COLOR: #ff00ff">max</span>
				<span style="COLOR: #000000">(wage) </span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> max_wage<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">group</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> id<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例2：查询订货量大于库存量的产品名称<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> name,库存量,</span>
				<span style="COLOR: #ff00ff">sum</span>
				<span style="COLOR: #000000">(订货量) </span>
				<span style="COLOR: #0000ff">as</span>
				<span style="COLOR: #000000"> sum_订货量<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">group</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> id, 库存量<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">having</span>
				<span style="COLOR: #000000"> 库存量</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #ff00ff">sum</span>
				<span style="COLOR: #000000">(订货量)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">order</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> id<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例3：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> 结束时期</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">January 1,2005</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例4：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">distinct</span>
				<span style="COLOR: #000000"> name)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>学起来也是怎么难，就是东西多而已<img height="19" src="http://www.cnitblog.com/Emoticons/77_77.gif" width="19" border="0" />！不是一般的多！<img src ="http://www.cnitblog.com/taihang/aggbug/11851.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-08 18:21 <a href="http://www.cnitblog.com/taihang/archive/2006/06/08/11851.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记－select下的四个重要子句用法</title><link>http://www.cnitblog.com/taihang/archive/2006/06/08/11846.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Thu, 08 Jun 2006 10:07:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/08/11846.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/11846.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/08/11846.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/11846.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/11846.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">group</span>
				<span style="COLOR: #000000"> by子句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">group</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">all</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000"> group_by_expression </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">with {cube|rollup}</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />cube:列的各种组合按组统计行<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />rollup：第一个分组条件指这一列统计行<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：</span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> name sex <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">group</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> name sex<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">with</span>
				<span style="COLOR: #000000"> cube<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />   </span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #0000ff">with</span>
				<span style="COLOR: #000000"> rollup<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />having子句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />和group BY子句通常一起使用,作用于组<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">having</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">search_condition</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">)：符合条件记录行数<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：查询有多个员工工资不低于1000的部门ID号<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> id,</span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> wage</span>
				<span style="COLOR: #808080">&gt;=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1000</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">group</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> id<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">having</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #808080">*</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">order</span>
				<span style="COLOR: #000000"> by子句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />排序方式<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">order</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000">{order_by_expression </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">asc|desc</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">}</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />asc升序，默认<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />desc降序<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：第一个字段升序，第二个字段降序<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> 字段1, 字段2<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">order</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> 字段1 </span>
				<span style="COLOR: #0000ff">desc</span>
				<span style="COLOR: #000000">,字段2<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：查询年龄最大的三个人<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">top</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
				<span style="COLOR: #000000"> name,age<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">order</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #0000ff">desc</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />compute子句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />在查询结果的末尾生成一个汇总数据行<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />computer<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />{{</span>
				<span style="COLOR: #ff00ff">avg</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #ff00ff">count</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #ff00ff">max</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #ff00ff">min</span>
				<span style="COLOR: #808080">|</span>
				<span style="COLOR: #ff00ff">sum</span>
				<span style="COLOR: #000000">} <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />(expression)} </span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">by expression [,<img src="http://www.cnitblog.com/images/dot.gif" />n</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">]<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />avg平均值，count计算行数，max最大值，min最小值,sum求和<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />expression:需要统计列的名称，此列必须在select列表中且不能用别名<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> expression:查询结果中生成分类统计的行，心须同时使用order by子句，expression是对应order </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />子句中的order_by_expression的子集或全集<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例：统计各个部门工资<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">select</span>
				<span style="COLOR: #000000"> name,department,wage<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> taihang<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">order</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> department<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">compute</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #ff00ff">sum</span>
				<span style="COLOR: #000000">(wage) </span>
				<span style="COLOR: #0000ff">by</span>
				<span style="COLOR: #000000"> department</span>
		</div>看的头都大了，有收获！！！<img src ="http://www.cnitblog.com/taihang/aggbug/11846.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-08 18:07 <a href="http://www.cnitblog.com/taihang/archive/2006/06/08/11846.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL学习笔记 where子句用法，like关键字</title><link>http://www.cnitblog.com/taihang/archive/2006/06/08/11816.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Thu, 08 Jun 2006 03:55:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/08/11816.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/11816.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/08/11816.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/11816.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/11816.html</trackback:ping><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">where子句<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />比较运算符：</span>
				<span style="COLOR: #808080">&lt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&lt;=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">&gt;=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">!=</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">!&lt;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">!&gt;</span>
				<span style="COLOR: #000000">. </span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">text</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">ntext</span>
				<span style="COLOR: #000000">,</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">image</span>
				<span style="COLOR: #000000">.型数据不可用。<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />范围说明：</span>
				<span style="COLOR: #808080">between</span>
				<span style="COLOR: #000000"> A </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000"> B,</span>
				<span style="COLOR: #808080">not</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">between</span>
				<span style="COLOR: #000000"> A </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000"> B.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />可选值列表: </span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">not</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000">.一般用于嵌套查询<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />模式匹配: </span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">not</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #000000">. <br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />是否空值:</span>
				<span style="COLOR: #0000ff">is</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">is</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">not</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">.<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />上述条件的逻辑组合：</span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">or</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #808080">not</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />内容大小写敏感<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />like关键字的通配符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">%</span>
				<span style="COLOR: #000000">，0或多个字符组成的字符串　<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />_，任意单个字符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[]</span>
				<span style="COLOR: #000000">，用于指定范围，例：</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">a-f</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">a至f范围内的任意单个字符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">^</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">，用于指定范围，例：</span>
				<span style="COLOR: #ff0000">[</span>
				<span style="COLOR: #ff0000">^a-f</span>
				<span style="COLOR: #ff0000">]</span>
				<span style="COLOR: #000000">a至f范围以外的任意单个字符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">mc%</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">%inger</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">_hery1</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">[m-z]inger</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">m[^c]%</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">%en%</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000"> </span>
		</div>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">用法：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />查询数值：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />字段 beteen </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />字段</span>
				<span style="COLOR: #808080">&gt;</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">7000</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />查询特定数值：<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />字段 </span>
				<span style="COLOR: #808080">in</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">1001</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">1003</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />查询name<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />字段 </span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">王__</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />通配符的转义字符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" /># </span>
				<span style="COLOR: #0000ff">escape</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">#</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">定义转义字符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例: 字段 </span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">sql#_m_il</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">escape</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">#</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />用</span>
				<span style="COLOR: #ff0000">[]</span>
				<span style="COLOR: #000000">将通配符指定为普通字符<br /><img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />例: 字段 </span>
				<span style="COLOR: #808080">like</span>
				<span style="COLOR: #ff0000">'</span>
				<span style="COLOR: #ff0000">%54[%]%</span>
				<span style="COLOR: #ff0000">'</span>
		</div>
<img src ="http://www.cnitblog.com/taihang/aggbug/11816.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-08 11:55 <a href="http://www.cnitblog.com/taihang/archive/2006/06/08/11816.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL select的基本语法</title><link>http://www.cnitblog.com/taihang/archive/2006/06/07/11774.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Wed, 07 Jun 2006 08:12:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/06/07/11774.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/11774.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/06/07/11774.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/11774.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/11774.html</trackback:ping><description><![CDATA[select的基本语法<br /><font style="BACKGROUND-COLOR: #ffffff"><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span> <span style="COLOR: #0000ff">select</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">all |distinct</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000"> select_list<br /></span><span style="COLOR: #008080">2</span> <span style="COLOR: #000000"></span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">into [new_table_name</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000">]<br /></span><span style="COLOR: #008080">3</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">from</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">table_name|view_name</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000">,<br /></span><span style="COLOR: #008080">4</span> <span style="COLOR: #000000">     </span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">table_name2|view_name2</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000"><img src="http://www.cnitblog.com/images/dot.gif" /><br /></span><span style="COLOR: #008080">5</span> <span style="COLOR: #000000"></span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">where search_conditions</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">6</span> <span style="COLOR: #000000"></span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">group by group_by_list</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">7</span> <span style="COLOR: #000000"></span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">having search_conditions</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">8</span> <span style="COLOR: #000000"></span><span style="COLOR: #ff0000">[</span><span style="COLOR: #ff0000">order by order_list[asc|desc</span><span style="COLOR: #ff0000">]</span><span style="COLOR: #000000">]</span></div></font>以前以为挺简单，后来发现挺复杂。<br /><img src ="http://www.cnitblog.com/taihang/aggbug/11774.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-06-07 16:12 <a href="http://www.cnitblog.com/taihang/archive/2006/06/07/11774.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ASP中十一种连接数据库的方法</title><link>http://www.cnitblog.com/taihang/archive/2006/04/15/9219.html</link><dc:creator>太行</dc:creator><author>太行</author><pubDate>Sat, 15 Apr 2006 14:27:00 GMT</pubDate><guid>http://www.cnitblog.com/taihang/archive/2006/04/15/9219.html</guid><wfw:comment>http://www.cnitblog.com/taihang/comments/9219.html</wfw:comment><comments>http://www.cnitblog.com/taihang/archive/2006/04/15/9219.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cnitblog.com/taihang/comments/commentRss/9219.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/taihang/services/trackbacks/9219.html</trackback:ping><description><![CDATA[
		<p>
				<font face="宋体" size="4">　　1.Access数据库的DSN-less连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adoconn.Open"Driver={Microsoft Access Driver(*.mdb)};DBQ="&amp; _<br />Server.MapPath("数据库所在路径")</font>
		</p>
		<p>
				<font face="宋体" size="4">　　2.Access OLE DB连接方法：<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Provider=Microsoft.Jet.OLEDB.4.0;"&amp; _<br />"Data Source=" &amp; Server.MapPath("数据库所在路径")</font>
		</p>
		<p>
				<font face="宋体" size="4">　　3.SQL server连接方法：<br />set adocon=server.createobject("adodb.recordset")<br />adocon.Open"Driver={SQL Server};Server=(Local);UID=***;PWD=***;"&amp; _<br />"database=数据库名;"</font>
		</p>
		<p>
				<font face="宋体" size="4">　　4.SQL server OLE DB连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"provider=SQLOLEDB.1;Data Source=RITANT4;"&amp; _<br />"user ID=***;Password=***;"&amp; _<br />"inital Catalog=数据库名"<br />　　<br />　　5.Oracle 连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;"</font>
		</p>
		<p>
				<font face="宋体" size="4">　　6.Oracle OLE DB 连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Provider=OraOLEDB.Oracle;data source=dbname;user id=admin;password=pass;"</font>
		</p>
		<p>
				<font face="宋体" size="4">　　7.dBase 连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq=------------;"</font>
		</p>
		<p>
				<font face="宋体" size="4">　　8.mySQL 连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Driver={mysql};database=yourdatabase;<br />uid=username;pwd=yourpassword;option=16386;"</font>
		</p>
		<p>
				<font face="宋体" size="4">　　9.Visual Foxpro 连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Driver={microsoft Visual Foxpro driver};sourcetype=DBC;sourceDB=*.dbc;Exclusive=No;"</font>
		</p>
		<p>
				<font face="宋体" size="4">　　10.MS text 连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;"&amp;_<br />"extensions=asc,csv,tab,txt;Persist SecurityInfo=false;"</font>
		</p>
		<p>
				<font face="宋体" size="4">　　11.MS text OLE DB 连接方法:<br />set adocon=Server.Createobject("adodb.connection")<br />adocon.open"Provider=microsof.jet.oledb.4.0;data source=your_path;"&amp;_<br />"Extended Properties'text;FMT=Delimited'"<br /><br /></font>
		</p>
<img src ="http://www.cnitblog.com/taihang/aggbug/9219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/taihang/" target="_blank">太行</a> 2006-04-15 22:27 <a href="http://www.cnitblog.com/taihang/archive/2006/04/15/9219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>