1、建用户
create user test_user identified by test_password;
create user test_user identified by test_password default tablespace ts_zzg; //直接在建用户的时候就赋予表空间
2、建表空间
create tablespace ts_zzg datafile 'f: s_zzgzzg_data.dbf' size 200M autoextend on next 50m maxsize 20480m
extent management local;
3、将表空间分配到用户
alter user test_user default tablespace ts_zzg;
4、用户授权
临时用户,特指不需要建表的用户,通常只赋予他们connect role.
grant create session,create table,create view,create sequence,create tablespace to test_user;
grant connect,resource,dba to test_user;
回收用户权限
revoke dba from test_user;
5、创建表
create table menu(
id varchar2(64) not null,
parent_id varchar2(64) not null,
name varchar2(100) not null,
depth number(2) not null,
primary key (id)
)
6、创建只读视图
create or replace view vw_employees as
select employee_id, employee_name, employee_position, employee_age
from employees
with read only;
7、登录用户
普通登录
conn test_user/test_password;
在服务器端免密码登陆oracle
在dos界面输入:sqlplus / as sysdba;
8、删除用户及相关对象
drop user test_user cascade;
9、数据库导入导出
exp:
1) 将数据库orcl完全导出
exp system/manager@orcl file=d:orcl_bak.dmp full=y
2) 将数据库中system用户的表导出
exp system/manager@orcl file=d:system_bak.dmp owner=system
3) 将数据库中表table1,table2导出,不导出数据
exp system/manager@orcl file=d: able_bak.dmp tables=(table1,table2) rows=no
4) 将数据库中的表customer中的字段mobile以"139"开头的数据导出
exp system/manager@orcl file=d:mobile_bak.dmp tables=customer query="where mobile like '139%' "
imp:
1) 将备份文件bak.dmp导入数据库
imp system/manager@orcl file=d:ak.dmp
如果数据表中表已经存在,会提示错误,在后面加上ignore=y就可以了。
2) 将备份文件bak.dmp中的表table1导入
imp system/manager@orcl file=d:ak.dmp fromuser=seapark tables=(table1)
10、创建dblink
- create /* public */ database link dblink1
- connect to dbusername identified by dbpassword
- using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))';
查询所有的dblink select * from dba_db_links;