复习数据库2
发布日期:2021-08-31 16:58:43 浏览次数:9 分类:技术文章

本文共 1887 字,大约阅读时间需要 6 分钟。

连接数据库

Conn scott/tiger@Orcl as Normal;

Disconn;

创建表空间

CREATE TABLESPACE DbDemo  DATAFILE 'DbDemo.dbf' size 400M autoextend on next 512M maxsize unlimited EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO

创建用户

-- Create the user

create user DbDemo

  identified by dbdemo

  default tablespace DBDEMO

  temporary tablespace TEMP

  profile DEFAULT;

-- Grant/Revoke role privileges

grant resource to DbDemo;

grant connect to DbDemo;

-- Grant/Revoke system privileges

grant unlimited tablespace to DbDemo;

 

修改用户的锁定

alter user DBDEMO  account lock;

-- Modify the user

alter user DBDEMO  account unlock;

修改用户密码

-- Modify the user

alter user DBDEMO  identified by "123";

创建表

-- Create DEPT table

create table DEPT

(

  deptno NUMBER(2) not null,

  dname  VARCHAR2(14),

  loc    VARCHAR2(13),

constraint PK_DEPT primary key (DEPTNO)

)

 

-- Create emp table

create table EMP

(

  empno    NUMBER(4) not null,

  ename    VARCHAR2(10),

  job      VARCHAR2(9),

  mgr      NUMBER(4),

  hiredate DATE,

  sal      NUMBER(7,2),

  comm     NUMBER(7,2),

  deptno   NUMBER(2),

constraint PK_EMP primary key (EMPNO)

)

 

alter table EMP  add constraint FK_DEPTNO foreign key (DEPTNO)

  references DEPT (DEPTNO);

 

增加记录

insert into emp (empno,ename,job,deptno) values(1233,'xiaoming','manager',20);

删除记录

delete from emp where empno=1233

更新记录

update emp set mgr=7092,ename='小明',Hiredate=to_date('19881027','yyyy/mm/dd') where empno=1234;

简单查询记录

select * from EMP t where job like 'CLERK';

关联查询

内连接

Select emp.empno,emp.ename,emp.job,dept.dname from emp,dept

Where emp.deptno=dept.deptno;

 

左外连接

Select emp.empno,emp.ename,emp.job,dept.dname from emp,dept

Where emp.deptno(+)=dept.deptno;

右外连接

Select emp.empno,emp.ename,emp.job,dept.dname from emp,dept

Where emp.deptno=dept.deptno(+);

子查询

在一个SQL语句中嵌套另一个SQL语句成为子查询。当一个问题无法通过一部解决时可考虑使用子查询,

一个出现在SELECT语句的FROM子句中的子查询被称为"内嵌视图";

一个出现在SELECT语句的WHERE子句中的子查询被称为"内嵌子查询",一个子查询能够包含另一个子查询,在一个顶级的查询中,Oracle数据库没有限制在FROM子句中的嵌套层数,可以在一个WHERE子句中嵌套255层子查询

转载地址:https://blog.csdn.net/weixin_34082789/article/details/85584201 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:设计模式名录
下一篇:POJ 1330 Nearest Common Ancestors (LCA,dfs+ST在线算法)

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年03月26日 16时30分16秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章