oracle表约束及复杂查询(oracle table constraints and complex queries)

oracle表约束及复杂查询(oracle table constraints and complex queries)

ID:12733006

大小:23.33 KB

页数:22页

时间:2018-07-18

oracle表约束及复杂查询(oracle table constraints and complex queries)_第1页
oracle表约束及复杂查询(oracle table constraints and complex queries)_第2页
oracle表约束及复杂查询(oracle table constraints and complex queries)_第3页
oracle表约束及复杂查询(oracle table constraints and complex queries)_第4页
oracle表约束及复杂查询(oracle table constraints and complex queries)_第5页
资源描述:

《oracle表约束及复杂查询(oracle table constraints and complex queries)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、oracle表约束及复杂查询(Oracletableconstraintsandcomplexqueries)grantresourcethatzy;grantdbaitzy;-1.表的约束-1.1非空约束:约束某个字段不为空droptablet_user;createtablet(_usert_numberintnotnullt_namevarchar2(255));-1.2唯一约束:约束某个字段只能是不重复的值altertablet_useraddconstraintt_number_uniqueunique(t_number);insertintot_uservalues(10

2、01,张三');insertintot_uservalues(1002,李四');insertintot_uservalues(1003,王五');-1.3检查约束:检查某个字段的值是否符合预设条件altertablet_useraddconstraintt_number_checkcheck(t_number<2000);insertintot_uservalues(2001,赵六');-1.4主键约束:一张表中,用来唯一区分两条记录的字段:默认非空且唯一altertablet_useraddt_idint;altertablet_useraddconstraintpkprimar

3、ykey_user_t(t_id);select*fromt_user;-1.5外键约束:表示了两张表的数据的联系(关联)createtablet(_departmentt_idintprimarykey,t_namevarchar2(255))altertablet_useraddt_didint;--增加一个字段,t_did表示员工属于的部门id-外键:员工表的字段t_did作为外键参照部门表的主键t_idaltertablet_useraddconstraintt_user_depart_fkforeignkey(t_did)referencest_department(t_i

4、d);select*fromt_department;insertintot_departmentvalues(1,'研发部');insertintot_departmentvalues(2,'市场部');commit;insertintot_uservalues(1004,小李,4.1);updatet_usersett=2,wheretis__id<=3;commit;deletefromtwheret__userid=3;-删除部门updatet_usersett_did=nullwheret_did=1;deletefromtwheret__departmentid=1;-2

5、.sql的基本语法和查询-2.1基本查询语句select*

6、[the]columnname

7、use[arg1,arg2...]fromtablename;-解锁scott账户alteruserscottaccountunlock;-全查询select*fromemp;-选定特定的列selectempno,ename,jobfromemp;-算术运算符+-*/selectename,sal*12fromtheesa;-空值:只要有空值参与的运算都为空selectename,comm,(1+2000)fromemp;-列的别名selectename,sal*12astotalsalfro

8、memp;-连接字符串select'姓名为'

9、

10、ename

11、

12、'的员工年薪是'

13、

14、sal*12fromtheesa;-distinct关键字selectdeptnofromemp;-过滤where子句select*fromempwheredeptno=30;-比较运算=,>,<,>=,<=,<>不等于select*fromempwheresal>1000;select*fromempwheredeptno<>10;-查询在1981年5月1日之后入职的员工select*fromempwherehiredate>_data(1981-05-01','yyyymmdd");-between

15、...and...select*fromempwheresalbetween1000and2000;-inselect*fromempwheresalin(1600170020002100);-like选择*从EMP在一个像“一%”;——名字以”“开头,%:多个字符选择*从EMP在不喜欢“%s”;——名字中含有的字符——逻辑运算或不选择*从EMP在萨尔>1000和表20;——从表前缀选择t.empno,t.ename从EMPT;通过子句排序秩序选择…从…[

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。