Oracle表空间创建及表创建

-- 创建表空间,(数据库文件)
create tablespace db3
datafile 'E: ablespacedb3.dbf'
size 1m
-- 创建表空间,(数据库文件),指定数据文件在哪儿 多大 扩容
create tablespace db2
datafile 'E: ablespacedb2.dbf'
size 1m autoextend on next 1m maxsize unlimited
-- 查询表
select * from user_tablespaces
-- 删除表空间
drop tablespace db3
-- 删除表空间及删除内容和文件
drop tablespace db3 including contents and datafiles
-- 更改表的状态
alter tablespace db3 read only
alter tablespace db3 read write


-- 创建用户,密码
create user user1 identified by user1
-- 删除用户
drop user user1
-- 创建用户,密码,同时更改默认表空间
create user user1 identified by user1
default tablespace db3
-- 创建后更改密码,更改默认表空间
alter user user1 identified by user2
alter user user1 default tablespace db3
-- 授权登录
grant create session to user1

-- 授予用户dba权限,管理员权限
grant dba to user1
-- 授予查询某个表权限
grant select on scott.dept to user1
-- 撤销权限
revoke dba from user1
revoke select on scott.dept from user1
-- user1创建表
create table student(id number,name varchar2(20),birthday date)
create table student2(id number(1),name varchar2(20),birthday date)
create table student3(id number(5),name varchar2(20),birthday date) -- number默认number(5)
-- 查表
select * from user_tables
select * from scott.dept -- 查询其他用户的表
select * from user_tab_cols
select * from user_tab_cols where table_name='STUDENT' -- 要和表中相同为大写
select * from user_tab_columns -- 和select * from user_tab_cols基本一样,少了几项
-- 删表
drop table student2
-- 增、改、删表中字段 使用 ()或者column
alter table student add chengji varchar2(10)
alter table student add (math number(1),english number(1)) -- 增加多个字段需用括号()
alter table student add (chengji2 varchar2(10)) -- 增 统一都使用()
alter table student rename (chengji to remark) -- xx
alter table student rename column chengji to remark -- 改 需使用关键字column
alter table student drop column chengji2 -- 删 需使用关键字column
alter table student drop (english) -- 删 使用()也行

-- 注释
comment on table student is '学生表'
comment on column student.id is '编号'

原文地址:https://www.cnblogs.com/21556guo/p/13525783.html