oracle语法大全

上传人:简****9 文档编号:99365669 上传时间:2019-09-18 格式:DOC 页数:29 大小:36.53KB
返回 下载 相关 举报
oracle语法大全_第1页
第1页 / 共29页
oracle语法大全_第2页
第2页 / 共29页
oracle语法大全_第3页
第3页 / 共29页
oracle语法大全_第4页
第4页 / 共29页
oracle语法大全_第5页
第5页 / 共29页
点击查看更多>>
资源描述

《oracle语法大全》由会员分享,可在线阅读,更多相关《oracle语法大全(29页珍藏版)》请在金锄头文库上搜索。

1、第一篇 基本操作-解锁用户 alter user 用户 account unlock;-锁定用户 alter user 用户 account lock;alter user scott account unlock;-创建一个用户yc 密码为a create user 用户名 identified by 密码;create user yc identified by a;-登录不成功,会缺少create session 权限,赋予权限的语法 grant 权限名 to 用户;grant create session to yc;-修改密码 alter user 用户名 identified by

2、 新密码;alter user yc identified by b;-删除用户drop user yc ;-查询表空间select *from dba_tablespaces;-查询用户信息select *from dba_users;-创建表空间create tablespace ycspacedatafile E:oracleappproduct11.2.0dbhome_1oradataycspace.dbfsize 2mautoextend on next 2m maxsize 5moffline ;-创建临时表空间create temporary yctempspacetempfil

3、e E:oracleappproduct11.2.0dbhome_1oradataycspace.dbfsize 2mautoextend on next 2m maxsize 5moffline ;-查询数据文件select *from dba_data_files;-修改表空间-1、修改表空间的状态-默认情况下是online,只有在非离线情况下才可以进行修改alter tablespace ycspace offline ; -离线状态,不允许任何对象对该表空间的使用,使用情况:应用需要更新或维护的时候;数据库备份的时候alter tablespace ycspace read write

4、;-读写状态alter tablespace ycspace online;alter tablespace ycspace read only; -只读,可以查询信息,可以删除表空间的对象,但是不能创建对象和修改对象 。使用情况:数据存档的时候-2、修改表空间的大小-增加文件的大小alter database datafile E:oracleappproduct11.2.0dbhome_1oradataycspace.dbf resize 10m;-增加数据文件alter tablespace ycspace add datafile E:oracleappproduct11.2.0dbh

5、ome_1oradataadd.dbf size 2m;-删除表空间的数据文件alter tablespace 表空间的名字 drop datafile 数据文件名;-删除表空间drop tablespace ycspace;-删除表空间且表空间中的内容和数据文件drop tablespace ycspace including contents and datafiles;-指定表空间 的 创建用户的语法create user yc1 identified by a default tablespace ycspace temporary tablespace temp;-删除用户drop

6、user yc1;-权限-赋予创建会话的权限grant create session to yc1;-创建一个表create table studentInfo(sid int,sname varchar2(10);-赋予yc1用户创建表的权限grant create table to yc1;-赋予yc1使用表空间的权限grant unlimited tablespace to yc1;-系统权限-对象权限-插入insert into studentInfo values (2,abcd);-查询select *from studentInfo;-修改update studentInfo s

7、et sid=1;-删除delete studentInfo ;drop table studentInfo; -系统权限删除表-赋权的语法-系统权限grant 权限名(系统权限或对象权限,角色,all) to 用户(角色,public) with admin option;-对象权限grant 权限名(系统权限或对象权限,角色,all) on 用户(角色,public) with grant option;-收权语法-系统权限revoke 权限名(系统权限或对象权限,角色,all) from 用户(角色,public) with admin option;-对象权限revoke 权限名(系统

8、权限或对象权限,角色,all) from 用户(角色,public) with grant option;-赋予创建用户的权限并且把这个权限传递下去,即yc1可以给别人赋权grant create user to yc1 with admin option;-收回权限,只能收回scottd ,不能收回由scott赋权的yc1的权限revoke create user from scott;-查看用户所具有的权限select *from user_sys_privs;-对象权限详解select * from emp;-使用yc1来查询scott里面的emp表select * from scott

9、.emp;-赋予yc1查询emp表和插入的权限grant select on emp to yc1;grant insert on emp to yc1;grant update(empno,ename) on emp to yc1;grant delete on emp to yc1;-对scott的emp表添加数据insert into scott.emp(empno,ename) value(111,acv);update scott.emp set ename=ycwhere empno=111;-赋予查询、赋予删除、添加、修改grant select on 表名 to 用户-gran

10、t select,delete,update,insert on 表名 to 用户grant select,delete,update,insert on emp to yc1;grant all on dept to yc1; -all代表所有的对象权限select *from scott.emp;select *from scott.dept;insert into scott.dept values(50,企事业文化部,bumen);-查看角色-dba:数据库管理员,系统最高权限,可以创建数据结构(表空间等)-resource:可以创建实体(表、视图),不可以创建数据库的结构-conne

11、ct:连接的权限,可以登录数据库,但是不可以创建实体和不可以创建数据库结构select *from role_sys_privs;grant connect to yc1;-将可以连接的角色赋予给yc1,则yc1就是应该可以连接数据库的人,类似于 create session 。create table StuInfos(sid int);select *from StuInfos;create table stuInfo(sid int primary key , -主键 primary key 非空且唯一 (主键约束)sname varchar2(10) not null, -姓名不能为空

12、,(非空约束)sex char(2) check(sex in(男,女), -(检查约束),check,age number(3,1) constraint ck_stuInfo_age check(age10 and age100) , -也可以用varchar ;age between 10 and 100 ,在10和100之间,是一个闭区间tel number(15) unique not null, -唯一约束,address varchar2(200) default 什么鬼)insert into stuInfo values(3,大大,男,18,4321543,default);

13、insert into stuInfo values(1,张三,男,10);select *from stuInfo;drop table stuInfo;create table classInfo(cid int primary key, -班级idcname varchar2(20) not null unique -班级名)create table stuInfo(sid int primary key,sname varchar2(20),cid int constraint fofk_stuInfo_cid references classInfo(cid) on delete c

14、ascade)insert into classInfo values(1,1班);insert into classInfo values(2,2班);insert into classInfo values(3,3班);insert into classInfo values(4,4班);select *from classInfo;select *from stuInfo;insert into stuInfo values(1001,张三,2);insert into stuInfo values(1002,张四,4);update classInfo set cid=1 where cid=8;drop table stuInfo;-要先删除这个drop table classInfo; -再删除这个delete classInfo where cid=4 ;-同时删除这两个表中的4-删除用户的时候drop user yc1 cascade -删除用户的同时把它创建的对象都一起删除-修改表-1

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号