﻿<?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博客-流水不腐，户枢不蠹-随笔分类-03数据库基础</title><link>http://www.cnitblog.com/funny/category/2951.html</link><description>swap, not lost! </description><language>zh-cn</language><lastBuildDate>Fri, 30 Sep 2011 16:43:21 GMT</lastBuildDate><pubDate>Fri, 30 Sep 2011 16:43:21 GMT</pubDate><ttl>60</ttl><item><title>SQL语句入门－－单表查询二</title><link>http://www.cnitblog.com/funny/archive/2006/06/09/11878.html</link><dc:creator>my whole world! </dc:creator><author>my whole world! </author><pubDate>Fri, 09 Jun 2006 03:46:00 GMT</pubDate><guid>http://www.cnitblog.com/funny/archive/2006/06/09/11878.html</guid><wfw:comment>http://www.cnitblog.com/funny/comments/11878.html</wfw:comment><comments>http://www.cnitblog.com/funny/archive/2006/06/09/11878.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/funny/comments/commentRss/11878.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/funny/services/trackbacks/11878.html</trackback:ping><description><![CDATA[4.2.5 组合条件的查询<br />    （1）在【命令编辑区】输入“select empno,ename,job from scott.emp where 
job&gt;=’CLERK’ and sal&lt;=2000”，然后单击【执行】按钮，得到逻辑与组合查询的结果。<br />     （2）在【命令编辑区】输入“select empno,ename,job from scott.emp where job&gt;=’CLERK’ or 
sal&lt;=2000”，然后单击【执行】按钮，得到逻辑或组合查询的结果。<br />     （3）在【命令编辑区】输入“select empno,ename,job from scott.emp where not 
job=’CLERK’”，然后单击【执行】按钮，得到逻辑非组合查询的结果。“not job=’CLERK’”等价于“job&lt;&gt;’CLERK’”。 组合条件中使用的逻辑比较符如表4.2所示。<br /><p>表4.2 逻辑比较符</p><table width="70%"><tbody><tr align="center"><td>名称</td><td>实例</td></tr><tr><td>and(与)</td><td>select * from scott.emp where job=’MANAGER’ and sal&lt;&gt;2000;</td></tr><tr><td>or (或)</td><td>select * from scott.emp where job!=’MANAGER’ or sal&lt;&gt;2000;</td></tr><tr><td>not(非)</td><td>select * from scott.emp where not job&gt;=’MANAGER’;</td></tr></tbody></table><br /><br />4.2.6 排序查询<br />    在【命令编辑区】输入“select empno,ename,job from scott.emp where 
job&lt;=’CLERK’ order by job asc,sal desc”，然后单击【执行】按钮，得到排序查询的结果。<br />   order by 可以指定查询结果如何排序，形式为字段名 
排序关键词；asc代表升序排列，desc代表降序排列，多个排序字段之间通过逗号分割。若有where查询条件，order by要放在where语句后面。<br /><br />4.2.7 分组查询<br />    分组查询是指将查询结果按照字段分组。<br />    （1）在【命令编辑区】输入“select 
empno,ename,job,sal from scott.emp group by job,empno,ename,sal having 
sal&lt;=2000”，然后单击【执行】按钮，得到分组查询的结果。   <br /><br />    （2）在【命令编辑区】输入“select 
empno,ename,job,sal from scott.emp where sal&lt;=2000 group by 
job,empno,ename,sal”，然后单击【执行】按钮，得到分组查询的结果。<br />     where检查每条记录是否符合条件，having是检查分组后的各组是否满足条件。having语句只能配合group 
by语句使用，没有group by时不能使用having，但可以使用where。<br /><br />4.2.8 
字段运算查询<br />    可以利用几种基本的算术运算符来查询数据。<br />    常见的+（加）、-（减）、*（乘）、/（除）4种算术运算都可以用来查询数据。<br />    在【命令编辑区】输入“select 
empno,ename,sal,mgr,sal+mgr from 
scott.emp”，然后单击【执行】按钮，得到结果。<br />    利用算术运算符仅仅适合多个数值型字段或字段与数字之间的运算。<br />4.2.9 
变换查询显示<br />    在【命令编辑区】输入“select empno 编号,ename 姓名,job 工作,sal 薪水 from 
scott.emp”，然后单击【执行】按钮，得到结果，可以将默认的字段名以设定的名称显示。<br />   <br />    以上我们学习了对单个数据表的查询语句。将上面这些基本的实例经过组合，就可以完成基本的日常数据查询任务，接下来进一步学习多表查询。<br /><br /><br /><br /><img src ="http://www.cnitblog.com/funny/aggbug/11878.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/funny/" target="_blank">my whole world! </a> 2006-06-09 11:46 <a href="http://www.cnitblog.com/funny/archive/2006/06/09/11878.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL语句入门－－单表查询一</title><link>http://www.cnitblog.com/funny/archive/2006/06/09/11877.html</link><dc:creator>my whole world! </dc:creator><author>my whole world! </author><pubDate>Fri, 09 Jun 2006 03:41:00 GMT</pubDate><guid>http://www.cnitblog.com/funny/archive/2006/06/09/11877.html</guid><wfw:comment>http://www.cnitblog.com/funny/comments/11877.html</wfw:comment><comments>http://www.cnitblog.com/funny/archive/2006/06/09/11877.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/funny/comments/commentRss/11877.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/funny/services/trackbacks/11877.html</trackback:ping><description><![CDATA[SQL语言按照功能可以分为4大类。<br />    数据查询语言DQL：查询数据。<br />    数据定义语言DDL：建立、删除和修改数据对象。<br />    数据操纵语言DML：完成数据操作的命令，包括查询。<br />    数据控制语言DCL：控制对数据库的访问，服务器的关闭、启动等<br /><br />单表查询是相对多表查询而言的，指从一个数据表中查询数据。<br />4.2.1 查询所有的记录<br />    在【命令编辑区】执行输入“select * from 
scott.emp”，然后单击【执行】按钮，得到emp数据表所有记录。<br /> select * from 数据表，这里的“*”代表数据表中所有的字段。<br /><br />4.2.2 查询所有记录的某些字段<br />    在【命令编辑区】输入“select empno,ename,job from 
scott.emp”，然后单击【执行】按钮，将显示emp数据表的empno、ename和job字段。<br />    select 字段名1, 字段名2,…… from 数据表，将显示某些特定的字段，注意这里的字段名之间的逗号是英文状态下的逗号。<br /><br />4.2.3 
查询某些字段不同记录<br />    在查询到的job字段中，可以发现有相同的数据，为了查询有多少种不同的job，在【命令编辑区】输入“select 
distinct job from scott.emp”，然后单击【执行】按钮，出现结果。<br />   select distinct 字段名 from 
数据表，这里的“distinct”保留字指在显示时去除相同的记录，与之对应的是“all”将保留相同的记录，默认为“all”。<br /><br />4.2.4 单条件的查询<br />    （1）在【命令编辑区】输入“select empno,ename,job from scott.emp where 
job=’MANAGER’”，然后单击【执行】按钮，出现的字符型字段条件查询的结果，查询的是job为MANAGER的记录。<br />    （2）在【命令编辑区】输入“select empno,ename,sal from scott.emp where 
sal&lt;=2500”，然后单击【执行】按钮，出现的数字型字段条件查询的结果，查询的是满足sal小于等于2500的记录。<br />    where可以指定查询条件，如果是指定字符型字段查询条件，形式为字段名 运算符 '字符串'；如果是指定数字型字段查询条件，形式为字段名 运算符 '字符串'。 
单条件查询使用的比较运算符如下表所示。<br /><br /><p>表4.1 比较运算符</p><table width="90%"><tbody><tr align="center"><td>名称</td><td>实例</td></tr><tr><td rowspan="2">=(等于)</td><td>select * from scott.emp where job=’MANAGER’;</td></tr><tr><td>select * from scott.emp where sal=1100;</td></tr><tr><td rowspan="2">!= (不等于)</td><td>select * from scott.emp where job!=’MANAGER’;</td></tr><tr><td>select * from scott.emp where sal!=1100;</td></tr><tr><td rowspan="2">^=(不等于)</td><td>select * from scott.emp where job^=’MANAGER’;</td></tr><tr><td>select * from scott.emp where sal^=1100;</td></tr><tr><td rowspan="2">&lt;&gt;(不等于)</td><td>select * from scott.emp where job&lt;&gt;’MANAGER’;</td></tr><tr><td>select * from scott.emp where sal&lt;&gt;1100;</td></tr><tr><td rowspan="2">&lt;(小于)</td><td>select * from scott.emp where sal&lt;2000;</td></tr><tr><td>select * from scott.emp where job&lt;’MANAGER’;</td></tr><tr><td rowspan="2">&gt;(大于)</td><td>select * from scott.emp where sal&gt;2000;</td></tr><tr><td>select * from scott.emp where job&gt;’MANAGER’;</td></tr><tr><td rowspan="2">&lt;=(小于等于)</td><td>select * from scott.emp where sal&lt;＝2000;</td></tr><tr><td>select * from scott.emp where job&lt;＝’MANAGER’;</td></tr><tr><td rowspan="2">&gt;=(大于等于)</td><td>select * from scott.emp where sal&gt;=2000;</td></tr><tr><td>select * from scott.emp where job&gt;=’MANAGER’;</td></tr><tr><td rowspan="2">in(列表)</td><td>select * from scott.emp where sal in (2000,1000,3000);</td></tr><tr><td>select * from scott.emp where job in (’MANAGER’,’CLERK’);</td></tr><tr><td rowspan="2">not in(不在列表)</td><td>select * from scott.emp where sal not in (2000,1000,3000);</td></tr><tr><td>select * from scott.emp where job not in (’MANAGER’,’CLERK’);</td></tr><tr><td rowspan="2">between(介于之间)</td><td>select * from scott.emp where sal between 2000 and 3000;</td></tr><tr><td>select * from scott.emp where job between ’MANAGER’ and ’CLERK’;</td></tr><tr><td rowspan="2">not between (不介于之间)</td><td>select * from scott.emp where sal not between 2000 and 3000;</td></tr><tr><td>select * from scott.emp where job not between ’MANAGER’ and 
’CLERK’;</td></tr><tr><td rowspan="2">like(模式匹配)</td><td>select * from scott.emp where job like ’M%’;</td></tr><tr><td>select * from scott.emp where job like ’M__’;</td></tr><tr><td rowspan="2">not like (模式不匹配)</td><td>select * from scott.emp where job not like ’M%’;</td></tr><tr><td>select * from scott.emp where job not like ’M__’;</td></tr><tr><td rowspan="2">Is null (是否为空)</td><td>select * from scott.emp where sal is null;</td></tr><tr><td>select * from scott.emp where job is null;</td></tr><tr><td rowspan="3">is not null(是否为空)</td><td>select * from scott.emp where sal is not null;</td></tr><tr><td>select * from scott.emp where job is not null;</td></tr></tbody></table>     like和not like适合字符型字段的查询，%代表任意长度的字符串，_下划线代表一个任意的字符。like ‘m%’ 
代表m开头的任意长度的字符串，like ‘m__’ 代表m开头的长度为3的字符串。<br /><br /><br /><img src ="http://www.cnitblog.com/funny/aggbug/11877.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/funny/" target="_blank">my whole world! </a> 2006-06-09 11:41 <a href="http://www.cnitblog.com/funny/archive/2006/06/09/11877.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关系型数据库系统简介</title><link>http://www.cnitblog.com/funny/archive/2006/06/08/11815.html</link><dc:creator>my whole world! </dc:creator><author>my whole world! </author><pubDate>Thu, 08 Jun 2006 03:45:00 GMT</pubDate><guid>http://www.cnitblog.com/funny/archive/2006/06/08/11815.html</guid><wfw:comment>http://www.cnitblog.com/funny/comments/11815.html</wfw:comment><comments>http://www.cnitblog.com/funny/archive/2006/06/08/11815.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/funny/comments/commentRss/11815.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/funny/services/trackbacks/11815.html</trackback:ping><description><![CDATA[原文网址：http://www.ddvip.com/database/oracle/index1/1.htm<br /><font color="#009900">绿色字体为我学习过程中添加的注释。</font><br /><br /><br />1.1.1 什么是关系型数据<br />    关系型数据是以关系数学模型来表示的数据。关系数学模型中以二维表的形式来描述数据，如表1.1和表1.2所示。<br /><br /><img src="file:///C:/Documents%20and%20Settings/crystal1/My%20Documents/My%20Pictures/Snap1.jpg" /><br /><br /><br />1.1.2 什么是关系型数据库<br />    1. 
什么是主码（主键）<br />    能够唯一表示数据表中的每个记录的【字段】或者【字段】的组合就称为主码。<br />    2. 
什么是外码（外键）<br />    表1.2的【编号】字段和表1.1的【导师编号】字段是对应的。表1.2中的【编号】字段是表1.2的主码。表1.2中的【编号】字段又可以称为是表1.1的外码。<br /><br /><font color="#009900">数据模型三要素：数据结构－－描述静态特性<br />                数据操作－－描述动态特性<br />                完整性约束<br />数据结构：包括两类，一类是与数据类型、内容、性质相关的对象，如关系模型中的域、属性、关系等；<br />          一类是与数据之间的联系相关的对象。如</font><font color="#009900">关系模型中的</font><font color="#009900">联系。<br />数据操作：  检索、插入、删除、修改等。已相关语言实现。<br /></font><font color="#009900">完整性约束： 约束条件，是一组数据完整性规则的集合。保证数据的正确性、有效性、一致性。<br /><br />关系数据模型：由若干个关系模式组成，</font><font color="#009900">关系模式由关系、关系上定义的操作和对关系的完整性规则组成。<br />              关系模型的逻辑结构是二维表，如表1.1,表名，表项名为属性，表内容为关系；行称为元组，各元素称为分量。<br /><br /></font>1.1.3 
什么是关系型数据库系统<br />    一个完整的关系型数据库系统包含5层结构，如图1.1所示。<br /><img src="file:///C:/Documents%20and%20Settings/crystal1/Local%20Settings/Temporary%20Internet%20Files/Content.IE5/SD6VWT6J/1-1%5B1%5D.jpg" /><br /><br />1. 硬件<br />    硬件指安装数据库系统的计算机，包括两种。<br />    服务器<br />    客户机<br />    2. 
操作系统<br />    操作系统指安装数据库系统的计算机采用的操作系统。<br />    3. 
关系型数据库管理系统、数据库<br />    关系型数据库是存储在计算机上的、可共享的、有组织的关系型数据的集合。关系型数据库管理系统是位于操作系统和关系型数据库应用系统之间的数据库管理软件。<br />    4. 
关系型数据库应用系统<br />    关系型数据库应用系统指为满足用户需求，采用各种应用开发工具（如VB、PB和Delphi等）和开发技术开发的数据库应用软件。<br />    5. 
用户<br />    用户指与数据库系统打交道的人员，包括如下3类人员。<br />    最终用户<br />    数据库应用系统开发员<br />    数据库管理员<br /><br /><font color="#009900">数据库系统的三级模式结构和二级映像：<br />外模式： 子模式、用户模式。一个数据库可有多个外模式，一个外模式可以对应一个用户或一个用户组。<br />外模式/概念模式映像：DBMS在此确定应该从何处读取概念模式中的相应记录。<br />概念模式：模式、逻辑模式。所有用户的公共数据视图。<br /></font><font color="#009900">概念</font><font color="#009900">模式/内模式映像：DBMS在此确定从哪些物理文件采取何种存取方法，读入哪些物理记录。</font><br /><font color="#009900">内模式： 物理模式。<br /><br /></font><br />1.1.4 
什么是关系型数据库管理系统   <font color="#009900">（DBMS）</font><br />    1. 数据定义语言及翻译程序DDL<br />    2. 数据操纵语言及编译（解释）程序DML<br />    3. 
数据库管理程序<br /><font color="#009900"><br /></font><br /><br />1.2.1 桌面关系型数据库系统<br />1.2.2 网络关系型数据库系统<br />    在网络关系型数据库系统中，有3个特别重要的概念。<br />    1. 
数据库服务器<br />    逻辑上的服务器指的是安装在计算机上提供一些基于网络环境的应用的软件。<br />    2. 
管理客户机<br />    逻辑上的管理客户机是指对数据库进行管理的软件。<br />    3. 
端口<br />    为了区分这些不同的逻辑服务器，使用了称为端口的概念。<br /><br /><br /><img src ="http://www.cnitblog.com/funny/aggbug/11815.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/funny/" target="_blank">my whole world! </a> 2006-06-08 11:45 <a href="http://www.cnitblog.com/funny/archive/2006/06/08/11815.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>