Oracle common usage summary

Recently, there are a lot of operations on databases, and I have summarized some commonly used sentences! ! !

(1) Oracle's default user

用户名:scott      密码: tiger                  权限:普通用户
用户名:sys        密码: change_on_install      权限:系统管理员
用户名:system     密码: manager                权限:本地管理员

If login directly with sqlplus sys/change_on_install is unsuccessful, you can change to sqlplus sys as sysdba/change_on_install

(2) Create a table space

--创建永久表空间
create tablespace tablename--表空间名称
datafile '路径+文件名.dbf'    --文件路径及文件名
size 20480M   --表空间大小
AUTOEXTEND ON NEXT 500M   --每次自动扩展500M
--创建临时表空间
create temporary tablespace tablename
tempfile  '路径+文件名.dbf'
size 500M

(3) Expand the table space

alter tablespace tablename add datafile '路径+文件名.DBF' size 20000M autoextend on next 500M maxsize unlimited;

(4) Temporarily change the size of the table space

ALTER TABLESPACE tablename ADD TEMPFILE '路径+文件名.dbf' size 20000M autoextend on next 50M maxsize unlimited;

(5) Delete the table space

 --删除空的表空间,但是不包含物理文件 
drop tablespace tablespace_name; 
--删除非空表空间,但是不包含物理文件 
drop tablespace tablespace_name including contents; 
--删除空表空间,包含物理文件 
drop tablespace tablespace_name including datafiles; 
--删除非空表空间,包含物理文件 
drop tablespace tablespace_name including contents and datafiles; 
--如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS 
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;

Reference: https://blog.csdn.net/gbj890229/article/details/6623996

(6) Create a user

--创建用户
create user username identified by password
default tablespace  tablename;

(7) Delete user

--删除用户
drop user username cascade;

(8) Delete the table space

#删除表空间
drop tablespace tablename including contents and datafiles;

(9) Authorize users

DBA: Has all privileges and is the highest authority of the system. Only a DBA can create a database structure.

RESOURCE: Users with Resource permissions can only create entities, not database structures.

CONNECT: Users with Connect permissions can only log in to Oracle, and cannot create entities or database structures.

For ordinary users: grant connect, resource permissions.

For DBA management users: grant connect, resource, dba permissions.

grant connect,resource to username;

(10) imp import sql file

imp username/password file=路径+文件名.sql full=y

(11) Query the size of the table space

select

  a.a1 表空间名称,

  c.c2 类型,

  c.c3 区管理,

  b.b2/1024/1024 表空间大小M,

  (b.b2-a.a2)/1024/1024 已使用M,

  substr((b.b2-a.a2)/b.b2*100,1,5) 利用率

  from

  (select tablespace_name a1, sum(nvl(bytes,0)) a2 from dba_free_space group by tablespace_name) a,

  (select tablespace_name b1,sum(bytes) b2 from dba_data_files group by tablespace_name) b,

  (select tablespace_name c1,contents c2,extent_management c3 from dba_tablespaces) c

  where a.a1=b.b1 and c.c1=b.b1;

(12) Find the name of the table where a field is located

--查找当前用户下某个字段所属的表
select *
  from user_tab_columns t
 where t.COLUMN_NAME = 'CONS_ID';

 

Guess you like

Origin blog.csdn.net/qq_28409193/article/details/108992558