zoukankan      html  css  js  c++  java
  • ORACLE之表

    本文章中的表在以后的例子中会用到。

    首先有t_fn_person和t_fn_dept表。

     1 create table t_fn_person(map_id NUMBER(10) primary key not null,
     2                          person_code VARCHAR2(20) not null,
     3                          person_name VARCHAR2(20) not null,
     4                          sex VARCHAR2(10),
     5                          insert_time date,
     6                          update_time date,
     7                          position VARCHAR2(20),
     8                          Salary NUMBER(12, 2),
     9                          Dept number);
    10 create table t_fn_dept(DEPT_ID NUMBER PRIMARY KEY NOT NULL,
    11                        DEPT_NO VARCHAR2(15) NOT NULL,
    12                        DLOCATION VARCHAR2(15));

    建立t_fn_person和t_fn_dept的外键(可以不建)

    1 alter table t_fn_person add constraint fk_fn_dept foreign key(dept) references t_fn_dept(dept_id);--建立外键

     更改列名一致及删除外键

    alter table t_fn_person drop constraint   fk_fn_dept
    alter table t_fn_person RENAME  COLUMN  Dept to DEPT_ID 

    插入数据

    insert into t_fn_person values(10001,'20001','Lily','F',sysdate,sysdate,'PM',2000,301);
    insert into t_fn_person values(10002,'20002','Tom','M',sysdate,sysdate,'PM',3000,301);
    insert into t_fn_person values(10003,'20003','Cat','F',sysdate,sysdate,'DM',1000,302);
    insert into t_fn_person values(10004,'20004','Dog','M',sysdate,sysdate,'CM',4000,303);
    insert into t_fn_person(map_id,person_code,person_name,sex,insert_time,update_time,position,Salary) values(10005,'20005','Xxx','M',sysdate,sysdate,'CM',3000);
    
    insert into t_fn_dept values(301,'301','shanghai');
    insert into t_fn_dept values(302,'302','wuhan');
    insert into t_fn_dept values(303,'303','shenzhen');
    insert into t_fn_dept values(304,'304','beijing');

     结果:

     

  • 相关阅读:
    第七十三天 how can I 坚持
    [leetcode]Climbing Stairs
    poj1204之AC自动机
    [leetcode]Sqrt(x)
    hibernate配置文件hibernate.cfg.xml的详细解释
    画板社交工具开发分享——HTML5 canvas控件、PHP、社交分享学习(一)
    我的计算几何学题目分类
    追梦
    mysql实现增量备份
    [leetcode]Plus One
  • 原文地址:https://www.cnblogs.com/hoaprox/p/5318877.html
Copyright © 2011-2022 走看看