Oracle 基本操作一:创建表空间、创建用户并赋予权限、创建表、维护表

来源:互联网 发布:怀化学院网络管理系统 编辑:程序博客网 时间:2024/05/17 01:42
--创建表空间
create tablespace npl01 datafile 'D:\developPrograms\Oracle\oradata\orcl\npl01.dbf' size 20M autoextend off;
--删除表空间,同时删除表空间所在的物理文件
drop tablespace npl01 including contents and datafiles;
--查询所有的表空间
select * from dba_free_space;
--创建用户
create user npl identified by 111111 default tablespace npl Temporary tablespace temp;
--查询所有用户
select * from all_users;
--权限包括系统权限(操作库)和对象权限(操作表,视图,序列等)
--赋权过程:权限给角色(多对多),角色给用户(多对多)
--赋连接权限给npl,并且npl可以给其它用户赋予权限
grant connect to npl with admin option;
--赋予建表、视图,查询等权限
grant resource to npl with admin option
--赋予DBA权限:数据库管理员角色,具有所有admin的系统权限,也可赋予其它用户
grant DBAto npl with admin option
--删除权限
revoke connect to npl 
--数据类型:char(存储固定字节数)  varchar(可以存空字符串)varchar2(空字符串存为null)
--创建表
create table tb_class(
 id number,
 code varchar2(18)
)
--维护表(增加列,修改列,删除列)要求是对象的拥有者
alter table tb_student add email varchar2(50);
alter table tb_student modify email varchar2(100);
alter table tb_student drop column iphone;
--修改字段名
alter table tb_student rename column iphone to phone; 
--修改表名
rename tb_student to tb_stu
--增加注释:表注释和列注释
comment on table tb_stu is '学生表';
comment on column tb_stu.phone is '手机号码';
--查看数据字典
select * from user_tables;--当前用户下的表
select * from user_tab_comments where comments is not null;--当前用户下的表的注释不是空
select * from user_col_comments where comments is not null;--当前用户下的表的列注释不是空
--删除表:删除所有数据和结构
drop table tb_class;
--删除表:级联删除表的约束
drop table tb_class cascade constraints;
--恢复删除的表
flashback table tb_class to before drop;
--删除表中所有数据 ,保留表结构
truncate tb_class;
--彻底删除表
drop table tb_class purge;
0 0
原创粉丝点击