Oracle实用操作

时间:2023-03-09 13:40:55
Oracle实用操作

查询用户下所有表:select * from tab;

删除表: drop table 表名;

但是删除表后还是会查询到BIN开头的垃圾表,drop后的表存在于回收站:

清空回收站所有表:  purge recyclebin;

打开/创建文本: ed 文件名.sql

执行文本脚本: @ 文件名.sql

创建表(创主键):

create table company(
cid number() primary key,
cname varchar2(20) not null
);

创建表(创复合主键):

create table company(
cid number(11),
cname varchar2(20) not null,
constraint pk_company primary key(cid)
);

创建表(创外键):

create table emp(
eid number(11) primary key,
ename varchar2(20) not null,
cid number() references company(cid)
);

创建表(创复合外键):

create table emp(
  eid number(11) not null,
  ename varchar2(20) not null,
  cid number(11),
  constraint pk_emp primary key(eid),
  constraint fk_emp_company foreign key(cid) references company(cid)
);

左外连接与又外连接语法:  select * from A表 right/left outer join B表 on A.字段 = B.字段;

说明: 若是left则以左边的表为基准,若是right则以右边的表为基准。

select * from emp e right outer join company c on e.CID = c.CID;
select * from emp e left outer join company c on e.CID = c.CID;
select * from company c left outer join emp e on e.CID = c.CID;
select * from company c right outer join emp e on e.CID = c.CID;