在MySQL中创建Oracle中的dept、emp、bonus、salgrade表

Oracle数据库中自带的4张表: dept、emp、bonus和salgrade是练习SQL查询的经典案例表,本文提供在MySQL中建这4张表的SQL语句

1. 创建dept表

CREATE TABLE `dept`(
    `deptno` INT(2) NOT NULL, 
    `dname` VARCHAR(14),
    `loc` VARCHAR(13),
    CONSTRAINT pk_dept PRIMARY KEY(deptno)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO dept VALUES (10,'ACCOUNTING','NEW YORK'); 
INSERT INTO dept VALUES (20,'RESEARCH','DALLAS'); 
INSERT INTO dept VALUES (30,'SALES','CHICAGO');  
INSERT INTO dept VALUES (40,'OPERATIONS','BOSTON');

2. 创建emp表

CREATE TABLE `emp` (
    `empno` int(4) NOT NULL PRIMARY KEY,
    `ename` VARCHAR(10),  
    `job` VARCHAR(9),  
    `mgr` int(4),  
    `hiredate` DATE,  
    `sal` float(7,2),  
    `comm` float(7,2),  
    `deptno` int(2),
    CONSTRAINT fk_deptno FOREIGN KEY(deptno) REFERENCES dept(deptno)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO EMP VALUES (7369,'SMITH','CLERK',7902,'1980-12-17',800,NULL,20); 
INSERT INTO EMP VALUES (7499,'ALLEN','SALESMAN',7698,'1981-02-20',1600,300,30);
INSERT INTO EMP VALUES (7521,'WARD','SALESMAN',7698,'1981-02-22',1250,500,30); 
INSERT INTO EMP VALUES (7566,'JONES','MANAGER',7839,'1981-04-02',2975,NULL,20); 
INSERT INTO EMP VALUES (7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250,1400,30); 
INSERT INTO EMP VALUES (7698,'BLAKE','MANAGER',7839,'1981-05-01',2850,NULL,30); 
INSERT INTO EMP VALUES (7782,'CLARK','MANAGER',7839,'1981-06-09',2450,NULL,10); 
INSERT INTO EMP VALUES (7788,'SCOTT','ANALYST',7566,'1987-07-13',3000,NULL,20); 
INSERT INTO EMP VALUES (7839,'KING','PRESIDENT',NULL,'1981-11-07',5000,NULL,10); 
INSERT INTO EMP VALUES (7844,'TURNER','SALESMAN',7698,'1981-09-08',1500,0,30); 
INSERT INTO EMP VALUES (7876,'ADAMS','CLERK',7788,'1987-07-13',1100,NULL,20); 
INSERT INTO EMP VALUES (7900,'JAMES','CLERK',7698,'1981-12-03',950,NULL,30); 
INSERT INTO EMP VALUES (7902,'FORD','ANALYST',7566,'1981-12-03',3000,NULL,20); 
INSERT INTO EMP VALUES (7934,'MILLER','CLERK',7782,'1982-01-23',1300,NULL,10);

3. 创建bonus表

CREATE TABLE `bonus`(
    `ename` VARCHAR(10),
    `job` VARCHAR(9),
    `sal` INT, 
    `comm` INT
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

4. 创建salgrade表

CREATE TABLE `salgrade` (  
    `grade` int, 
    `losal` int,  
    `hisal` int
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

INSERT INTO SALGRADE VALUES (1,700,1200); 
INSERT INTO SALGRADE VALUES (2,1201,1400); 
INSERT INTO SALGRADE VALUES (3,1401,2000); 
INSERT INTO SALGRADE VALUES (4,2001,3000); 
INSERT INTO SALGRADE VALUES (5,3001,9999);

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏c#开发者

biztalk rosettanet 自定义 pip code

USE [BTARNDATA] GO /****** Object: StoredProcedure [dbo].[proc_GetActivityStatu...

27111
来自专栏程序猿

4.3.4.7 Pattern Matching

MySQL provides standard SQL pattern matching as well as a form of pattern matchi...

3076
来自专栏跟着阿笨一起玩NET

SQL Server 2008中的Pivot和UnPivot

今天给新成员讲解PIVOT 和 UNPIVOT示例,顺便整理了一下其用法。这是自SQL Server 2005起提供的新功能。

682
来自专栏后端之路

优化sql系列之Show Warnings

我们平时使用explain来查看相关的执行计划 SELECT sum(t.amount) + IFNULL(sum(t.vip_expense), 0...

3008
来自专栏程序猿

MySQL Regular Expression

MySQL provides standard SQL pattern matching as well as a form of pattern matchi...

3546
来自专栏Spring相关

mysql 查询当天、本周,本月,上一个月的数据

DATE_ADD(createTime,INTERVAL 1 DAY) 得到指定日期后一天的日期/把1改为任意数字就可以得到后N天的日期

5403
来自专栏杨建荣的学习笔记

一条执行时间两天半的sql语句简化(r4笔记第62天)

周末刚过去,今天来到办公室做例行检查,就发现一条sql语句已经执行234841秒(65小时),已经两天多了。 查看了一下对应的Undo资源消耗,发现这个语句是最...

2908
来自专栏Android知识点总结

SpringBoot-14-MyBatis预热篇,MySQL小结

新建一个测试表:将sword_insert_test中test_name赋值为sword表中id大于5的name

1741
来自专栏IT开发技术与工作效率

MySQL #{驼峰字段} for MyBatis

782
来自专栏cloudskyme

分区表建立索引

全局索引 ============ CREATE INDEX month_ix ON sales(sales_month) 本地索引 ============...

32110

扫码关注云+社区