Oracle 表详解(table)

1 概述

1. 作用: '存储数据'(逻辑结构上) 
         -- 物理结构上是:数据文件

2 表管理

2.1 命名规范

1. 必须以 '字母' 开头,可由 '字母、数字、_、$、#' 组成
2. 长度不能超过 30 个字符       -- 超过则报错提醒
3. 避免使用 Oracle 的 '关键字'  -- 否则查询方式为: ."关键字"
4. 在创建表、列时,Oracle 会自动转为 '大写'

2.2 设计规范:范式

2.3 信息查询

-- 权限范围由大到小: dba_* > all_* > user_*
1. 表、列创建查询
   (1) select * from dba_tables;  -- 表
   (2) select * from dba_tab_columns t order by t.column_id; -- 列
   
2. 表、列备注查询
   (1) select * from dba_tab_comments;  -- 表备注
   (2) select * from dba_col_comments;  -- 列备注

3 表操作

3.1 创建表

create table scott.student_info (
   sno         number(10) constraint pk_student_info_sno primary key,
   sname       varchar2(30) not null,
   create_date date not null,
   create_user varchar2(50) not null,
   update_date date not null,
   update_user varchar2(50) not null
);

-- 备注信息
comment on table scott.student_info is '学生信息表';
comment on column scott.student_info.sno is '学号';
comment on column scott.student_info.sname is '姓名';
comment on column scott.student_info.create_date is '创建日期';
comment on column scott.student_info.create_user is '创建人';
comment on column scott.student_info.update_date is '更新日期';
comment on column scott.student_info.update_user is '更新人';

-- 授权给其它用户,如:hr
grant select on scott.student_info to hr;

3.2 修改表

-- 演示修改 1 列 或 多 列
1. '增加'
   alter table scott.student_info add address varchar2(50); 
   alter table scott.student_info add (id_type varchar2(1), id_no varchar2(10));
   
2. '修改'
   -- 数据类型
   alter table scott.student_info modify (address varchar2(100));
   alter table scott.student_info modify (id_type varchar(2), id_no varchar2(20));
   -- 列名
   alter table scott.student_info rename column address to new_address;
   -- 表名(新名称不需要带 属主)
   alter table scott.student_info rename to new_student_info;
   alter table scott.new_student_info rename to student_info;
   
3. '删除' -- 删除单列时,才需要加关键字 column
   alter table scott.student_info drop column new_address;
   alter table scott.student_info drop (id_type, id_no);

3.3 删除表

-- 删除表(表结构 + 表数据)
drop table scott.student_info;

-- 清空表(仅清空表数据)
truncate table scott.student_info; 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼丸丶粗面

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值