• oracle 创建表、删除表、添加字段、删除字段、表备注、字段备注、修改表属性


    1、创建表

     create table 表名(
            classid number(2) primary key,
                 表字段     数据类型    是否允许为空(not null:不为空/null:允许空)    默认值(default 'XXX')
           );
    -- Create table
    create table STUDENT.stuinfo
    (
      stuid      varchar2(11) not null,--学号:'S'+班号(7位数)+学生序号(3位数)(1)
      stuname    varchar2(50) not null,--学生姓名
      sex        char(1) not null,--性别
      age        number(2) not null,--年龄
      classno    varchar2(7) not null,--班号:'C'+年级(4位数)+班级序号(2位数)
      stuaddress varchar2(100) default '地址未录入',--地址 (2)
      grade      char(4) not null,--年级
      enroldate  date,--入学时间
      idnumber   varchar2(18) default '身份证未采集' not null--身份证
    )-- Add comments to the table 
    comment on table STUDENT.stuinfo --(4)
      is '学生信息表';
    -- Add comments to the columns 
    comment on column STUDENT.stuinfo.stuid -- (5)
      is '学号';
    comment on column STUDENT.stuinfo.stuname
      is '学生姓名';
    comment on column STUDENT.stuinfo.sex
      is '学生性别';
    comment on column STUDENT.stuinfo.age
      is '学生年龄';
    comment on column STUDENT.stuinfo.classno
      is '学生班级号';
    comment on column STUDENT.stuinfo.stuaddress
      is '学生住址';
    comment on column STUDENT.stuinfo.grade
      is '年级';
    comment on column STUDENT.stuinfo.enroldate
      is '入学时间';
    comment on column STUDENT.stuinfo.idnumber
      is '身份证号';

    代码解析:

    (1)处: not null 表示学号字段(stuid)不能为空。

    (2)处:default 表示字段stuaddress不填时候会默认填入‘地址未录入’值。

    (3)处:表示表stuinfo存储的表空间是users,storage表示存储参数:区段(extent)一次扩展64k,最小区段数为1,最大的区段数不限制。

    (4)处:comment on table 是给表名进行注释。

    (5)处:comment on column 是给表字段进行注释。

    往表中添加一个字段,默认为一个表中的某一个值

    alter table PROJ add suggest AS (UPPER("PROJ_ID"))
    
    comment on column PROJ.Suggest is '模糊搜索列格式:xxx|yyy|zzz;默认:PROJ_ID';

    2、删除表(慎用)

     drop  table 表名

    3、给表加表备注

     comment on table 表名 is 'XXXXXX'

    4、给表字段加备注

     comment on column 表名.字段名 is 'XXXXX'

    5、修改表字段属性

     alter table 表名 modify (字段名 字段类型 默认值 是否为空);

    6、删除表字段

     alter table 表名 drop column 字段名

    7、添加表字段 

     格式:alter table 表名 add (字段名 字段类型 默认值 是否为空);
     
     例:alter table sf_users add (userName varchar2(30) default '' not null);

    8、修改表字段名称

     alter table 表名 rename column 旧列名 to 新列名;

    9、修改表名

     alter table 旧表名 rename to 新表名
  • 相关阅读:
    python面试大全
    python面试2
    python求职之路
    python面试题目
    关于栈的输入顺序和输出顺序
    表单提交中get和post方式的区别
    DOS命令行下mysql 基本命令
    跨站请求伪造CSRF
    Windows上python的virtualenv 安装及使用
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/11206021.html
Copyright © 2020-2023  润新知