/*Oracle基础(创建表空间、创建用户、授予权限、撤销权限、更改删除接锁用户)*/

时间:2022-05-28 08:46:55

创建表空间

create tablespace tablespace1 --表空间名字 datafile ‘D:\test.ora’ size 10M autoextend on;
create tablespace test datafile 'C:\t68\test.ora' size 10M autoextend on;
create tablespace test datafile 'C:\t68\test.ora' size 10M autoextend off;
create tablespace test datafile 'C:\t68\test.ora' size 10M autoextend on next 1024k;
--autoextend on next 1024K; 设置表空间自动扩展,每次1024K;

test为表空间名 datafile为数据文件。autoextend on 开启自动扩展,autoextend off 关闭自动扩展。

创建新用户

要连接到Oracle数据库, 就需要创建一个用户帐户,每个用户都有一个默认表空间和一个临时表空间,create user命令用于创建新用户。

create user newdream identified by dream1234 default tablespace tablespace1 (temporary临时 tablespace表空间 temp);
create user newdream identified by dream1234 default tablespace tablespace1 temporary tablespace temp;

这里newdream为用户名,dream1234为密码,tablespace1为表空间名。temporary tablespace temp 为临时表空间temp,然后执行。

授予权限

 a权限指的是执行特定命令或访问数据库对象的权

b权限有两种类型, 系统权限和对象权限
c系统权限允许用户执行某些数据库操作, 如创建表就
是一个系统权限
d对象权限允许用户对数据库对象(如表、 视图、 序列
等) 执行特定操作
e角色是一组相关权限的组合, 可以将权限授予角
色, 再把角色授予用户, 以简化权限管理。

grant 命令可用于为用户分配权限或角色

grant connect to newdream
grant resource to newdream
grant create sequence to martin

常用权限授予

alter user newdream quota unlimited on users;授予用户表空间权限(如果没有的话建表时会报没有表空间权限)
grant dba to newdream;
grant select on tablename to name; 给一个查询权限
grant select on test to martin;允许用户查询test表的记录
grant update on test to martin;允许用户更新test表中的记录
grant all on test to martin;允许用户插入、删除、更新和查询test表中的记录

撤销权限

grant select, update on order_master(表名) to newdream(用户名);授予权限
revoke select, update on order_master from newdream;撤销权限
grant dba to newdream;设置权限
revoke dba from newdream;撤销权限

更改和删除用户

alter user 命令可用于更改口令

alter user newdream identified by martinpass;修改 newdream 用户的密码

drop user 用于删除用户

drop user martin cascade

删除 martin 用户模式 CASCADE参数,删除用户的同时,删除用户下的全部objects对象

解锁用户

alter newdream(用户名) account unlock;解锁用户newdream
修改列的名字:
alter table student rename column address to newaddress
增加一列:
alter table student(表空间名) add (column int);

删除一列:
alter table student(表空间名)drop (column int);