用户
*.创建用户
create user chenbin identified by orcl;
*.显示当前用户
show user
*.修改密码
自己: password
别人: alter user chenbin identified by orcle;
*.删除用户
drop user chenbin;
drop user chenbin cascade;(用户已经建表)
*.切换用户
conn chenbin/orcl
*.授予用户权限
grant connect,resource,dba to chenbin;
授予用户chenbin赋予其他用去connect权限
grant connect,resource to chenbin with admin option;
*.对用户进行登录次数的权限设置,以及登录失败后解锁的时间
create profile lock_account limit failed_login_attempts 3 passwork_lock_time 2;
锁用户
alter user chenbin profile loack_account;
给用户解锁
alter user chenbin account unlock;
*.让用户定期修改登录密码
create profile aaa limit password_life_time 10
password_grace_time 2;
赋予用户chenbin
alter user chenbin profile aaa
删除文件
drop profile aaa (cascade/仅删除相关的属性)
*. 创建用户表空间
表空间名字: CREALE TABLESPACE chenbin_tablespace;
表空间物理文件位置: DATAFILE 'E:\oracle\product\10.2\oradata \JBITDB\EPET.DBF' SIZE 100M
数据字典
*.查询用户
desc dba_users;
select username from dba_users;
*.查询数据字典
系统权限 dba_sys_privs
对象权限 dba_tab_privs
列权限 dba_col_privs
用户所具有的角色 dba_role_privs
例如 desc dba_role_privs
select * from dba_role_privs where grantee='C';
*.查询oracle中所有的角色(dba)
select * from dba_roles;(55)
*.查询oracle中所有的系统权限(dba)
select * from system_privilege_map order by name;(208)
*.查询oracle中所有的对象权限(dba)
select distinct privilege from dba_tab_privs;(17)
*.查询数据库的表空间
select tablespace_name from dba_tablespaces;
*.查询角包含的系统权限
select * from dba_sys_privs where grantee='DBA';
*.显示当前用户可以访问的所有数据字典视图
select * from dict where commnets like '%grant%';
*.显示当前数据库的全称
select * from global_name;
表
*.查询表
自己:
只返回用户所对应方案的所有表
select table_name from user_tables;
返回用户可以访问的所有表
select tables_name from all_tables;
查询数据库所有的表
select table_name from dba_tables;
别人:
select * from all_tables where owner='chenbin';
*.导出表的命令
spool d:\aa.sql;
select * from uer;
spool off;
*.查看表结构
desc uer;
*.增加表字段
alter table uuu add (classid number(2));
*.删除表字段
alter table uuu drop column classsid;
*.修改表字段
alter table uuu modify (classid number(3));
*.修改表字段的类型或名字(不能有数据)
alter table uuu modify (classid char(30));
alter table uuu rename column classid to classid;
*.修改表名
rename uuu to uu;
*.删除表
drop table uuu;
*.插入日期格式
02-11月-1993
或者修改格式
alter session set nls_date_format='yyyy-mm-dd';
*.插入部分字段
insert into uuu(bir) values('1993-12-12');
*.插入为空
insert into uuu vaules('12312','1212','1212',null);
select * from uuu where bir is null;
*.修改
update uuu set bir='' where username='';
*.删除数据
savepoint a;
delete from uuu;删除所有记录,表结构还在,写日志,可以恢复,速度慢
rollback to a;回滚 truncate table uuu(不写日志);
drop table uuu; 删除表的结构和数据
*.打开操作时间
set timing on;
*.复制表数据
insert into uuu() select * from uuu;
*.显示多少行
select count(*) from uuu;
*.查询显示不重复的数据
select distinct deptno,job from emp;
*.把用户c下面的表权限授予/收回chenbin
授予查询/修改/增加、删除(在c用户的表uuu授予chenbin)
grant select/updata/insert/(all)delect on uuu to chenbin;
revoke select/updata/insert/(all)delect on uuu from chenbin;
授予chenbin可以把查看c用户的uuu表再授予别人
grant select/updata/insert/(all)delect on uuu to chenbin with grant option;
在chenbin用户下查询c用户的表uuu select * from c.uuu;
数据库
*.断开与数据库的链接
disc
*.编辑指定脚本
edit d:\a.sql
*.运行脚本
start或@ d:\a.sql
*.显示设置
show all可以显示当前相关的设置
设置显示行的宽度,默认是80个字符 show linesize
set linesize 90
*.查询当前日期
select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;
*.关闭/开启数据库(sys/system)
shutdown; startup
备份与恢复
*.数据库表的逻辑备份与恢复(数据库open)
C:\app\Administrator\product\11.2.0\dbhome_1\BIN
备份
export(工具)导出(备份)/导入(恢复)到磁盘中
1.导出表
exp userid=c/orcl@orcl tables=(uuu) file=c:\cc.dmp
exp userid=system/orcl@orcl tables=(c.uuu) file=c:\uuu1.dmp
1.1.导出表结构
exp userid=c/orcl@orcl tables=(uuu) file=c:\uuu2.dmp rows=n
1.2.直接到岀(大表)结构
exp userid=c/orcl@orcl tables=(uuu) file=c:\uuu3.dmp direct=y
2.导出方案
exp userid=c/orcl@orcl owner=c file=c:\c.dmp;
exp userid=system/orcl@orcl owner=(system,c) file=c:\c1.dmp;
3.导出数据库
exp userid=system/orcl@orcl full=y inctype=complete file=c:\x.dmp;
恢复
1.导入表
imp userid=c/orcl@orcl tables=(emp) file=c:\cc.dmp
imp userid=system/orcl@orcl tables=(emp2) file=c:\uu1.dmp towser=c;
1.1导入表结构emp
imp userid=c/orcl@orcl tables(emp3) file=c:\uu1.dmp rows=n;
1.2导入数据
imp userid=c/orcl@orcl tables(emp3) file=c:\uu1.dmp ignore=y;
2.导入方案
imp userid=c/orcl@orcl file=c:\x.dmp;
imp userid=system/orcl@orcl file=c:\c.dmp; fromuser=system towser=c
3.导入数据库
imp userid=system/orcl@orcl full=y file=c:\x.dmp;
*.创建用户
create user chenbin identified by orcl;
*.显示当前用户
show user
*.修改密码
自己: password
别人: alter user chenbin identified by orcle;
*.删除用户
drop user chenbin;
drop user chenbin cascade;(用户已经建表)
*.切换用户
conn chenbin/orcl
*.授予用户权限
grant connect,resource,dba to chenbin;
授予用户chenbin赋予其他用去connect权限
grant connect,resource to chenbin with admin option;
*.对用户进行登录次数的权限设置,以及登录失败后解锁的时间
create profile lock_account limit failed_login_attempts 3 passwork_lock_time 2;
锁用户
alter user chenbin profile loack_account;
给用户解锁
alter user chenbin account unlock;
*.让用户定期修改登录密码
create profile aaa limit password_life_time 10
password_grace_time 2;
赋予用户chenbin
alter user chenbin profile aaa
删除文件
drop profile aaa (cascade/仅删除相关的属性)
*. 创建用户表空间
表空间名字: CREALE TABLESPACE chenbin_tablespace;
表空间物理文件位置: DATAFILE 'E:\oracle\product\10.2\oradata \JBITDB\EPET.DBF' SIZE 100M
数据字典
*.查询用户
desc dba_users;
select username from dba_users;
*.查询数据字典
系统权限 dba_sys_privs
对象权限 dba_tab_privs
列权限 dba_col_privs
用户所具有的角色 dba_role_privs
例如 desc dba_role_privs
select * from dba_role_privs where grantee='C';
*.查询oracle中所有的角色(dba)
select * from dba_roles;(55)
*.查询oracle中所有的系统权限(dba)
select * from system_privilege_map order by name;(208)
*.查询oracle中所有的对象权限(dba)
select distinct privilege from dba_tab_privs;(17)
*.查询数据库的表空间
select tablespace_name from dba_tablespaces;
*.查询角包含的系统权限
select * from dba_sys_privs where grantee='DBA';
*.显示当前用户可以访问的所有数据字典视图
select * from dict where commnets like '%grant%';
*.显示当前数据库的全称
select * from global_name;
表
*.查询表
自己:
只返回用户所对应方案的所有表
select table_name from user_tables;
返回用户可以访问的所有表
select tables_name from all_tables;
查询数据库所有的表
select table_name from dba_tables;
别人:
select * from all_tables where owner='chenbin';
*.导出表的命令
spool d:\aa.sql;
select * from uer;
spool off;
*.查看表结构
desc uer;
*.增加表字段
alter table uuu add (classid number(2));
*.删除表字段
alter table uuu drop column classsid;
*.修改表字段
alter table uuu modify (classid number(3));
*.修改表字段的类型或名字(不能有数据)
alter table uuu modify (classid char(30));
alter table uuu rename column classid to classid;
*.修改表名
rename uuu to uu;
*.删除表
drop table uuu;
*.插入日期格式
02-11月-1993
或者修改格式
alter session set nls_date_format='yyyy-mm-dd';
*.插入部分字段
insert into uuu(bir) values('1993-12-12');
*.插入为空
insert into uuu vaules('12312','1212','1212',null);
select * from uuu where bir is null;
*.修改
update uuu set bir='' where username='';
*.删除数据
savepoint a;
delete from uuu;删除所有记录,表结构还在,写日志,可以恢复,速度慢
rollback to a;回滚 truncate table uuu(不写日志);
drop table uuu; 删除表的结构和数据
*.打开操作时间
set timing on;
*.复制表数据
insert into uuu() select * from uuu;
*.显示多少行
select count(*) from uuu;
*.查询显示不重复的数据
select distinct deptno,job from emp;
*.把用户c下面的表权限授予/收回chenbin
授予查询/修改/增加、删除(在c用户的表uuu授予chenbin)
grant select/updata/insert/(all)delect on uuu to chenbin;
revoke select/updata/insert/(all)delect on uuu from chenbin;
授予chenbin可以把查看c用户的uuu表再授予别人
grant select/updata/insert/(all)delect on uuu to chenbin with grant option;
在chenbin用户下查询c用户的表uuu select * from c.uuu;
数据库
*.断开与数据库的链接
disc
*.编辑指定脚本
edit d:\a.sql
*.运行脚本
start或@ d:\a.sql
*.显示设置
show all可以显示当前相关的设置
设置显示行的宽度,默认是80个字符 show linesize
set linesize 90
*.查询当前日期
select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;
*.关闭/开启数据库(sys/system)
shutdown; startup
备份与恢复
*.数据库表的逻辑备份与恢复(数据库open)
C:\app\Administrator\product\11.2.0\dbhome_1\BIN
备份
export(工具)导出(备份)/导入(恢复)到磁盘中
1.导出表
exp userid=c/orcl@orcl tables=(uuu) file=c:\cc.dmp
exp userid=system/orcl@orcl tables=(c.uuu) file=c:\uuu1.dmp
1.1.导出表结构
exp userid=c/orcl@orcl tables=(uuu) file=c:\uuu2.dmp rows=n
1.2.直接到岀(大表)结构
exp userid=c/orcl@orcl tables=(uuu) file=c:\uuu3.dmp direct=y
2.导出方案
exp userid=c/orcl@orcl owner=c file=c:\c.dmp;
exp userid=system/orcl@orcl owner=(system,c) file=c:\c1.dmp;
3.导出数据库
exp userid=system/orcl@orcl full=y inctype=complete file=c:\x.dmp;
恢复
1.导入表
imp userid=c/orcl@orcl tables=(emp) file=c:\cc.dmp
imp userid=system/orcl@orcl tables=(emp2) file=c:\uu1.dmp towser=c;
1.1导入表结构emp
imp userid=c/orcl@orcl tables(emp3) file=c:\uu1.dmp rows=n;
1.2导入数据
imp userid=c/orcl@orcl tables(emp3) file=c:\uu1.dmp ignore=y;
2.导入方案
imp userid=c/orcl@orcl file=c:\x.dmp;
imp userid=system/orcl@orcl file=c:\c.dmp; fromuser=system towser=c
3.导入数据库
imp userid=system/orcl@orcl full=y file=c:\x.dmp;