打年初换了工作至今近一年的时间里,大部分时间开发接口,顺带写点前端逻辑代码,数据库相关的用的不多,久了不用就生疏了,趁着18年的最后十来天,得空将数据库等之前的知识简单梳理下。
一,Oracle数据库的下载安装
官网提供的比较大,这里用的是精简版:
链接:https://pan.baidu.com/s/1hSU_DlZY4XQZWl9yzDPyZg
提取码:qkif
下载之后逐步安装,不再赘述。
二,建表
数据库安装成功之后,简单新建两张表:
表1 员工信息表emp_xiangyoulu, 表2 部门信息表dept_xiangyoulu
--1,创建员工实例表emp
CREATE TABLE emp_xiangyoulu(
empno NUMBER(4,0),
ename VARCHAR2(10),
job VARCHAR2(9),
mgr NUMBER(4,0),
hiredate DATE,
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(2,0)
);
--2,创建部门表dept
CREATE TABLE dept_xiangyoulu(
deptno NUMBER(2),
dname VARCHAR2(14),
loc VARCHAR2(13)
);
三,插入测试数据
1,员工信息表
--3,为emp插入数据
INSERT INTO emp_xiangyoulu
(empno,ename,job,mgr,hiredate,sal,comm,deptno)
VALUES(7369,'SMITH','CLERK',7902,TO_DATE('1980-12-17','YYYY-MM-DD'),800,NULL,20);
INSERT INTO emp_xiangyoulu
VALUES(7499,'ALLEN','SALESMAN',7698,TO_DATE('1981-2-20','YYYY-MM-DD'),1600,300,30);
INSERT INTO emp_xiangyoulu
VALUES(7521,'WARD','SALESMAN',7698,TO_DATE('1981-2-22','YYYY-MM-DD'),1250,500,30);
INSERT INTO emp_xiangyoulu
VALUES(7566,'JONES','MANAGER',7839,TO_DATE('1981-4-2','YYYY-MM-DD'),2975,NULL,20);
INSERT INTO emp_xiangyoulu
VALUES(7564,'MARTIN','SALESMAN',7698,TO_DATE('1981-9-28','YYYY-MM-DD'),1250,1400,30);
INSERT INTO emp_xiangyoulu
VALUES(7698,'BLAKE','MANAGER',7839,TO_DATE('1981-5-1','YYYY-MM-DD'),2850,NULL,30);
INSERT INTO emp_xiangyoulu
VALUES(7782,'CLARK','MANAGER',7839,TO_DATE('1981-6-9','YYYY-MM-DD'),2450,NULL,10);
INSERT INTO emp_xiangyoulu
VALUES(7788,'SCOTT','ANALYST',7566,TO_DATE('1987-4-19','YYYY-MM-DD'),3000,NULL,20);
INSERT INTO emp_xiangyoulu
VALUES(7839,'KING','PRESIDENT',NULL,TO_DATE('1981-11-17','YYYY-MM-DD'),5000,NULL,10);
INSERT INTO emp_xiangyoulu
VALUES(7844,'TURNER','SALESMAN',7698,TO_DATE('1981-9-8','YYYY-MM-DD'),1500,0,30);
INSERT INTO emp_xiangyoulu
VALUES(7876,'ADAMS','CLERK',7788,TO_DATE('1987-5-23','YYYY-MM-DD'),1100,NULL,20);
INSERT INTO emp_xiangyoulu
VALUES(7900,'JAMES','CLERK',7698,TO_DATE('1981-12-3','YYYY-MM-DD'),950,NULL,30);
INSERT INTO emp_xiangyoulu
VALUES(7902,'FORD','ANALYST',7566,TO_DATE('1981-12-3','YYYY-MM-DD'),3000,NULL,20);
INSERT INTO emp_xiangyoulu
VALUES(7934,'MILLER','CLERK',7782,TO_DATE('1982-1-23','YYYY-MM-DD'),1300,NULL,10);
2, 部门信息表
--为dept插入数据
INSERT INTO dept_xiangyoulu (deptno,dname,loc) VALUES(10,'ACCOUTING','NEW YORK');
INSERT INTO dept_xiangyoulu (deptno,dname,loc) VALUES(20,'RESEARCH','DALLAS');
INSERT INTO dept_xiangyoulu (deptno,dname,loc) VALUES(30,'SALES','CHICAGO');
INSERT INTO dept_xiangyoulu (deptno,dname,loc) VALUES(40,'OPERATIONS','BOSTON');
执行结束之后,进行查询操作:
SELECT * FROM emp_xiangyoulu;
SELECT * FROM dept_xiangyoulu;
能查出对应的插入数据即ok!