第一篇 基本操作
--解锁用户 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 新密码;
alter user yc identified by b;
--删除用户
drop user yc ;
--查询表空间
select *from dba_tablespaces;
--查询用户信息
select *from dba_users;
--创建表空间
create tablespace ycspace
datafile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\ycspace.dbf'
size 2m
autoextend on next 2m maxsize 5m
offline ;
--创建临时表空间
create temporary yctempspace
tempfile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\ycspace.dbf'
size 2m
autoextend on next 2m maxsize 5m
update语法大全
offline ;
--查询数据文件
select *from dba_data_files;
--修改表空间
--1、修改表空间的状态
--默认情况下是online,只有在非离线情况下才可以进行修改
alter tablespace ycspace offline ; --离线状态,不允许任何对象对该表空间的使用,使用情况:应用需要更新或维护的时候;数据库备份的时候
alter tablespace ycspace read write;--读写状态
alter tablespace ycspace online;
alter tablespace ycspace read only; --只读,可以查询信息,可以删除表空间的对象,但是不能创建对象和修改对象 。使用情况:数据存档的时候
--2、修改表空间的大小
--增加文件的大小
alter database datafile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\ycspace.dbf' resize 10m;
--增加数据文件
alter tablespace ycspace add datafile 'E:\oracle\app\product\11.2.0\dbhome_1\oradata\add.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 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 set 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 权限名(系统权限或对象权限,角,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 * p;
--赋予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 p(empno,ename) value(111,'acv');
p set ename='yc'where empno=111;
--赋予查询、赋予删除、添加、修改
grant select on 表名 to 用户
--grant select,delete,update,insert on 表名 to 用户
grant select,delete,update,insert on emp to yc1;
grant all on dept to yc1; --all代表所有的对象权限
select *p;
select *from scott.dept;
insert into scott.dept values(50,'企事业文化部','bumen');
--查看角
--dba:数据库管理员,系统最高权限,可以创建数据结构(表空间等)
--resource:可以创建实体(表、视图),不可以创建数据库的结构
--connect:连接的权限,可以登录数据库,但是不可以创建实体和不可以创建数据库结构
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, --姓名不能为空,(非空约束)
sex char(2) check(sex in('男','女')), --(检查约束),check,
age number(3,1) constraint ck_stuInfo_age check(age>10 and age<100) , --也可以用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);
insert into stuInfo values(1,'张三','男',10);
select *from stuInfo;
drop table stuInfo;
create table classInfo(
cid int primary key, --班级id
cname 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 cascade
)
insert into classInfo values(1,'1班');

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。