zoukankan      html  css  js  c++  java
  • 表基本信息修改

    示例操作如下

    --班级信息表
    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;

  • 相关阅读:
    C++中static修饰的静态成员函数、静态数据成员
    C++友元函数、友元类
    C++异常处理
    运行时类型识别RTTI
    AD转换
    敏捷模式下的测试用例该如何存在?
    使用Postman轻松实现接口数据关联
    接口测试Mock利器-moco runner
    python测开平台使用dockerfile构建镜像
    MySQL – 用SHOW STATUS 查看MySQL服务器状态
  • 原文地址:https://www.cnblogs.com/tianmingt/p/4434772.html
Copyright © 2011-2022 走看看