该文章为本人自学oracle时的部分笔记,适合oracle初学者,内容为oracle创建用户及初步建表的知识
》start D:/aaa.sql 打开一个文本内的sql语句
---------------------------------------------------------------------spool off 将sqlplus屏幕内容输出到指定的文件中去,用法如下:
》spool D:/bbb.sql;
》select * from emp;(看表的结构用:desc 表名)
》spool off; 将select* from emp的内容输出到 D:/bbb.sql文件中
----------------------------- 创建新用户---------------------------------------------
sys/system有权利创建用户
创建用户:create user 用户名 identified by 密码;用法如下:
①create user yang identified by tiger;(创建了一个用户名为yang,密码为tiger的用户)
删除用户:drop user 用户名;(如果用户有表存在则:drop user 用户名 cascade;)
解锁用户:alter user 用户名 account unlock;
-------------------------------- 赋予新用户登陆、创表、查询别人表的权利-------------------------------------------
直接创建的用户(如上的yang用户)是没有权限的,甚至连登陆权限也没有。所以需要用grant(
②grant connect to yang;(赋予登陆上数据库的权限,但yang用户还不能创建表))赋予用户权限,没收权限用revoke(revoke all/select on scott.emp from yang;)。
用户yang登陆上数据库后还不能建表,所以这里需要再赋予新建的用户创建表的权限:
③grant resource to yang; (现在用户yang可以建表了)
举个建表的简单例子,创建一个叫test的表
④create table test(userId varchar2(30),userName varchar2(30));
-----------------------------------------------------------增删改查别人的表-------------------------------------------------------------------
另:想要查询、修改别人的表等,这就要赋予yang查询、修改别人的表内容的相关权限
grant select on emp to yang; (scott授权yang可以查询Scott的emp表,同理也有insert,update等),
如果是system授权则是:
grant select on scott.emp to yang; (这要带上scott,说明是Scott的emp表,因为授权的是system,不写则是默认授权自己的表)
这里yang查询时:select * from scott.emp 。(也要带上scott,说明查询的表是scott这家伙的)
注意:grant all on scott.emp to yang;则表示把这张表的增、删、改、查权限都交给yang这用户,要注意这样操作!!。
----------------------------------------------------------------------------------------------------------------------------------------------
权限的传递:
grant select on scott.emp to yang with grant option;(system给yang查询scott的emp这表的权限,而且yang用户还可以传递这查询权限给别人。)
-------------------------------------- 管理口令(profile)3次登陆失败则锁用户账户2天----------------------------------------------
》create profile aaaaa limit fail_login_attempts 3 password_lock_time 2;
》alter user yang profile aaaaa;(这里aaaaa是profile文件的名字,相当于创建了一个叫aaaaa的规定,规定内容:3次密码错误则锁定用户2天,并把这规定强加给yang)
system帮忙解锁
解锁用户:alter user 用户名 account unlock;
》删除profile文件:drop profile 文件名 cascade;