《Oracle数据库用户管理源代码.docx》由会员分享,可在线阅读,更多相关《Oracle数据库用户管理源代码.docx(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Oracle数据库用户管理源代码创立用户sqlplus/nologconn sys/ldm as sysdba;create user ul identified by 1dm default tablespace users temporary tablespace temp quot IM on users account lock;更改用户create tablespace tldatafile e:tl_0Ldbf size 2M autoallocate;alter user ul default tablespace tl quota IM on tl account unlock
2、 /删除用户drop user ul cascade;查询用户创立用户u2create user u2 identified by qy default tablespace tl;可以通过某些视图(如dba_users)来查看数据库中该用户的一些信息column username format alOcolumn profile format alOcolumn status format alOselect username,profile,account_status status,createdfrom dba_userswhere username=U2,;通过desc dba_us
3、ers命令来显示dba_users的其他列desc dba_users查询用户所使用的表空间及其配额select tablespace_name the_name,username,blocksfrom dba_ts_quotas;权限管理为用户ul授予create session系统权限sqlplus/nologcreate user ul identified by 1dm conn ul/ldm as sysdba;grant create session to ul;为用户授予某角色所具有的所有权限conn sys/ldm as sysdba;create role rl;grant
4、create session,create table, create trigger,create procedureto rlwith admin option;回收系统权限conn ul/ldmcolumn username format alOcolumn privilege format a20select * from user_sys_privs;conn sys/ldm as sysdba;revoke create session,grant any rolefrom u 1;为用户授予对象权限conn sys/ldm as sysdba;create table table
5、 1(id char(10);insert into tabletvalues(nWelcome!n);grant select on sys.tablel to u2;conn u2/ldmselect * from sys.tablel;基本对象管理表管理在做表管理的实验时,先需要以管理员身份创立一个表空间,并在该表空间上创立自己做实验要用的用户,同时为该用户授权,每个实验组以这一用户登录后进行本节的实验。conn sys/ldm as sysdbmcreate tablespace ts8 datafile fts8_l.dbf size 10M;create user u22 iden
6、tified by 1dmdefault tablespace ts8;grant dba to u22;conn u22/ldm;创立表student,包含三个字段(id、name和address),每个字段都具有各自的属 性create table student(id char(5),name varchar( 10),address varchar2(50);向表student插入一条数据:insert into studentvalues,Tist;山西太原迎泽大街226号);另外一种方式来创立表create table student_copy as select * from s
7、tudent;增加 列alter table student add telephone char(15);判断是否更改成功desc student;修改表名称rename student to stu;删除表drop table student_copy;查看表desc student_copy;创立视图create view stu_view(name,telephone)asselect name,telephone form stu;查看select * from stu view;向视图中插入数据insert into stu_viewvalues(王五,查看select * from stu view;删除视图drop view stu_view;其他数据库对象的管理create synonym si for stu;查看select * from s 1;创立序列IdSeq,并在向表stu插入数据时用其值来填充idcreate sequence Idseq increcement by 2 start with 3 maxvalues 900; insert into stuvalues(Idseq.nextVal,null,null,null);查看select * from stu;