zoukankan      html  css  js  c++  java
  • 建张表

    最近重新开始找工作,把以前的东西捡一捡......仅做记录 


    参考链接:Oracle 基本 以及 plsql 语句

    --建表
    create table interview_20190405(
           id varchar(5),
           number_of_times varchar(2)  not null, 
           company_name varchar(48) not null,
           channel varchar(32) ,
           interview_time date,
           address varchar(48),
           interview_question varchar(20),
           interview_result varchar(500)
    )
    
    --修改表名
    rename interview_20190405 to interview;
    
    --增加字段
    alter table interview add create_time date;
    alter table interview add update_time date;
    
    select * from interview;
    
    --Oracle不能直接在建表的时候写注释,而是以comment on 的形式在建好表之后加上注释
    comment on table interview is '面试记录';
    comment on column interview.number_of_times is '第几次面试';
    comment on column interview.company_name is '公司名称';
    comment on column interview.channel is '面试来源渠道';
    comment on column interview.interview_time is '面试时间';
    comment on column interview.address is '面试地址';
    comment on column interview.interview_question is '面试中提到的问题';
    comment on column interview.interview_result is '面试结果';
    
    --看一下上面加的注释
    select * from user_col_comments t where t.TABLE_NAME like '%INTERVIEW%';
    select * from user_tab_comments t where t.TABLE_NAME like '%INTERVIEW%';
    
    --增加约束,设置主键
    alter table interview add constraints interview_pk primary key (id);
    
    --新建一个sequence,用来设置主键自增长
    create sequence interview_seq minvalue 1 maxvalue 999 start with 1 increment by 1;
    
    --正式用之前得先取一下值,相当于宣告一下我要用这个序列了,给一个初始值
    select  interview_seq.nextval from dual;
    
    --修改字段
    alter table interview modify (interview_question varchar(500));
    
    --新增一条数据
    insert into interview
    values
      (interview_seq.currval,
       '1',
       '深圳市XXX科技有限公司',
       '智联',
       to_date('2019-04-02 10:00:00', 'yyyy-mm-dd hh24:mi:ss'),
       '深圳市XX区',
       '学了啥啊',
       '不去',
       sysdate,
       sysdate);
       
    select * from interview t where t.id = '1';
      
    update interview t  set t.update_time = sysdate where t.id = '1'; 
    -------------------------------------------------------------------------------------------------------------------------------------------------------------- 白云苍狗时光飞,嘻嘻哈哈一生追。哈!
  • 相关阅读:
    regedit注册表
    Environment应用
    VMI帮助类
    Image帮助类
    asp.net core+Postman
    printf和cout的区别详述
    C++指针
    Qt button和buttons区别
    visual studio收函数
    编译警告
  • 原文地址:https://www.cnblogs.com/sangong/p/10661143.html
Copyright © 2011-2022 走看看