Oracle12c 数据库建表空间及数据操作

更新时间:2023-09-17 23:44:01 阅读量: 幼儿教育 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Oracle12c 数据库建表空间及数据操作

--1、创建名字叫Java31的表空间

create tablespace Java31 datafile 'D:\\app\\hanq8202\\oradata\\orcl\\Java31.DBF' size 50M autoextend on next 32M maxsize unlimited;

--2、创建新用户c##hanq,在Oracle12c中必须在用户名前添加c##前缀

create user c##hanq identified by hq198202 default tablespace Java31;

--3、删除一个用户

drop user c##JAVA31 cascade;--用户已经被删除了 drop tablespace JAVA31 ;--用户已经被删除了

--4、给c##hanq用户添加权限

--授予用户权限的语法:gran 权限|角色 to 用户 --用户权限有:

--①、create session // 创建session的权限,即登陆权限 --②、unlimited tablespace //用户使用表空间的权限 --③、grant unlimited tablespace to tablename;//授予tablename用户使用表空间的权限

--④、grant create table to tablename;//授予创建表的权限

--⑤、grant drop any table to tablename;//授予删除表的权限,注意要加any关键字 --⑥、grant insert any table to tablename;//插入表的权限 注意要加any关键字 --⑦、grant update table to tablename;//修改表的权限 注意要加any关键字 --⑧、grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public) grant connect ,resource to c##hanq; grant create table to c##hanq; grant drop any table to c##hanq; grant insert any table to c##hanq; grant update any table to c##hanq;

grant create view to c##hanq; grant select any table to c##hanq; grant dba to c##hanq;

--5、撤销用户的权限

--语法:revoke 权限|角色 from 用户名 revoke dba from c##hanq;

--6、创建表

--create [schema.]table (column datatype(length));

--schema:模式名,如果是在自己的模式中建表,模式名可以不写; --table:表名; --column:列名;

--datatype:数据类型; --length:数据宽度; create table stuInf (

stId number(30) not null primary key ,--学号 stName varchar2(100) not null,--姓名 stAge number(30) not null,--年龄 stGender varchar2(10)--性别 );

create table stuScore(

Scid number(30) not null, score number(10,1), stuId number (30) );

--7、alert table修改命令

alter table stuInf modify ( stId number(25));--修改stId列的属性

alter table stuInf add ( stuAdd varchar2(100),stuTel varchar2(30));--添加stuAdd和stuTel列

alter table stuInf add ( stuNo number(30));--添加stuNo列 alter table stuInf drop column stuNo;--删除stuNo列 alter table stuInf add ( stuEntrance date );

--8、truncate table 命令,不删除表结构的情况下,删除表中的所有行

truncate stuInf;

--9、desc命令,显示表结构

description stuInf;--在pl/sql环境下运行为无效的sql,在sqlplus下运行可以看到表结构

--10、sql语句创建、删除、查看约束

alter table stuInf add constraint UN_stTel unique (stuTel);--为stuTel列添加唯一键 alter table stuScore add constraint FK_stuId foreign key (stuId) references stuInf(stId);--为stuScore表中stuId添加外键,关联到stuInf表的stID alter table stuInf drop constraint UN_stTel ;--删除stuTel列的唯一建

--11、查看约束

select * from user_constraints where table_name ='stuInf'; select * from user_constraints where table_name ='stuScore';

--12、给表格添加数据

insert into stuInf (stId,stName,stAge,stGender,stuAdd,stuTel) values(1,'tom',20,'mail','USA','0987623'); select * from stuInf; insert into stuInf (stId,stName,stAge,stGender,stuAdd,stuTel,Stuentrance) values(2,'Andy',19,'femail','UK','987512',sysdate);--sysdate系统时间

update stuInf set stuEntrance = to_date('1980-12-23','yyyy-MM-dd') where stId =1;

本文来源:https://www.bwwdw.com/article/8mbh.html

Top