• 表基本信息修改


    示例操作如下

    --班级信息表
    create table t_class_info(
    classno number(3) primary key,
    classname varchar2(10),
    classplace varchar2(13)
    );

    --学生信息表
    create table t_student_info(
    stuno number(3),
    classno number(3),
    stuname varchar2(10),
    stusex char(1),
    stucontect number(11),
    stuadd varchar2(50),
    studetailinfo varchar2(100)
    );

    --重命名表
    alter table t_class_infot rename to t_class_info

    --修改列名
    alter table t_class_info rename column classplace to location;

    --添加主键约束
    alter table t_student_info add constraint pk_stu_no primary key(stuno);


    --添加外键约束
    alter table t_student_info add constraint fk_classno foreign key(classno) references t_class_info(classno);

    --添加check约束
    alter table t_student_info add constraint ck_stu_info check (stusex in ('f','m'));

    alter table ttt add constraint index_age check (age>0 and age<50)

    --添加not null约束
    alter table t_student_info modify stucontect constraint not_null_info not null;

    --添加unique约束
    alter table t_student_info add constraint uq_stu_contect unique(stucontect);

    --添加default约束
    alter table t_student_info modify stusex char(2) default'm';

    --增加列
    alter table t_student_info add stuid varchar2(18);
    alter table t_student_info add stuage date default sysdate not null;

    --删除列
    alter table t_student_info drop column studetailinfo;

    --修改列的长度,长度只能由小改成大,如果要改小,则要删除该字段下的值
    alter table t_class_info modify classplace varchar2(50);

    --修改列的精度
    alter table t_student_info modify stuno number(2);

    --修改列的数据类型
    alter table t_student_info modify stusex char(2);

    --修改列的默认值
    alter table t_student_info modify stuage default sysdate+1;

    --禁用约束
    alter table t_student_info disable fk_classno;

    --启用约束
    alter table t_student_info enable fk_classno;

    --删除约束,如果有外键约束则要先删除外键表中的
    alter table t_student_info drop fk_classno;

    --延迟约束
    alter table t_student_info add constraint fk_classno foreign key(classno)
    references t_class_info(classno)
    deferrable initially deferred;

    --向表中添加注释
    comment on table t_student_info is '学生表';

    --向列添加注释
    comment on column t_student_info.stuname is '学生姓名';
    comment on column t_class_info.classname is '班级';

    --清除表中所有数据
    truncate table t_student_info;
    --删除表
    drop table t_student_info;


    --删除表不经过回收站
    drop table t_student_info purge;


    --闪回被删除的表
    flashback table t_student_info to before drop;

  • 相关阅读:
    ES6:Iterator遍历器
    前端:对BFC的理解
    前端:性能优化之防抖与节流
    ES6新增数据类型Symbol
    ajax和fetch、aixos的区别
    我对js数据类型的理解和深浅(copy)的应用场景
    egg的基本使用
    前端:css3的过渡与动画的基础知识
    Java基础篇之类
    JAVA基础篇之Scanner
  • 原文地址:https://www.cnblogs.com/tianmingt/p/4434772.html
Copyright © 2020-2023  润新知