mysql+oracle创建表并插入大量数据脚本
时间:2020-06-10
本文章向大家介绍mysql+oracle创建表并插入大量数据脚本,主要包括mysql+oracle创建表并插入大量数据脚本使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
####MySql####
use stu;
drop table if exists student; create table student ( s_id int(11) not null auto_increment , sno int(11), sname varchar(50), sage int(11), ssex varchar(8) , father_id int(11), mather_id int(11), note varchar(500), primary key (s_id), unique key uk_sno (sno) ) engine=innodb default charset=utf8mb4; truncate table student; delimiter $$ drop function if exists insert_student_data $$ create function insert_student_data() returns int deterministic begin declare i int; set i=1; while i<50000000 do insert into student values(i ,i, concat('name',i),i,case when floor(rand()*10)%2=0 then 'f' else 'm' end,floor(rand()*100000),floor(rand()*1000000),concat('note',i) ); set i=i+1; end while; return 1; end$$ delimiter ; select insert_student_data(); select count(*) from student; use stu; create table course ( c_id int(11) not null auto_increment , cname varchar(50) note varchar(500), primary key (c_id) ) engine=innodb default charset=utf8mb4; truncate table course; delimiter $$ drop function if exists insert_course_data $$ create function insert_course_data() returns int deterministic begin declare i int; set i=1; while i<=1000 do insert into course values(i , concat('course',i),floor(rand()*1000),concat('note',i) ); set i=i+1; end while; return 1; end$$ delimiter ; select insert_course_data(); select count(*) from course; use stu; drop table if exists sc; create table sc ( s_id int(11), c_id int(11), t_id int(11), score int(11) ) engine=innodb default charset=utf8mb4; truncate table sc; delimiter $$ drop function if exists insert_sc_data $$ create function insert_sc_data() returns int deterministic begin declare i int; set i=1; while i<=50000000 do insert into sc values( i,floor(rand()*1000),floor(rand()*10000000),floor(rand()*750)) ; set i=i+1; end while; return 1; end$$ delimiter ; select insert_sc_data(); commit; select insert_sc_data(); commit; create index idx_s_id on sc(s_id) ; create index idx_t_id on sc(t_id) ; create index idx_c_id on sc(c_id) ; select count(*) from sc; use stu; drop table if exists teacher; create table teacher ( t_id int(11) not null auto_increment , tname varchar(50) , note varchar(500),primary key (t_id) ) engine=innodb default charset=utf8mb4; truncate table teacher; delimiter $$ drop function if exists insert_teacher_data $$ create function insert_teacher_data() returns int deterministic begin declare i int; set i=1; while i<=10000000 do insert into teacher values(i , concat('tname',i),concat('note',i) ); set i=i+1; end while; return 1; end$$ delimiter ; select insert_teacher_data(); commit; select count(*) from teacher;
####Oracle####
create tablespace scott_data datafile '/home/oracle/oracle_space/sitpay1/scott_data.dbf' size 1024m autoextend on; create tablespace scott_index datafile '/home/oracle/oracle_space/sitpay1/scott_index.dbf' size 64m autoextend on; create temporary tablespace scott_temp tempfile '/home/oracle/oracle_space/sitpay1/scott_temp.dbf' size 64m autoextend on; drop user scott cascade; create user scott identified by tiger default tablespace scott_data temporary tablespace scott_temp ; grant resource,connect,dba to scott; drop table student; create table student ( s_id number(11) , sno number(11) , sname varchar2(50), sage number(11), ssex varchar2(8) , father_id number(11), mather_id number(11), note varchar2(500) ) nologging; truncate table student; create or replace procedure insert_student_data is q number(11); begin q:=0; for i in 1..50 loop insert /*+append*/ into student select rownum+q as s_id,rownum+q as sno, concat('sutdent',rownum+q ) as sname,floor(dbms_random.value(1,100)) as sage,'f' as ssex,rownum+q as father_id,rownum+q as mather_id,concat('note',rownum+q ) as note from dual connect by level<=1000000; q:=q+1000000; commit; end loop; end insert_student_data; / call insert_student_data(); alter table student add constraint pk_student primary key (s_id); commit; select count(*) from student; create table course ( c_id number(11) primary key, cname varchar2(50), note varchar2(500) ) ; truncate table course; create or replace procedure insert_course_data is q number(11); begin for i in 1..1000 loop insert /*+append*/ into course values(i , concat('name',i),concat('note',i) ); end loop; end insert_course_data; / call insert_course_data(); commit; select count(*) from course; create table sc ( s_id number(11), c_id number(11), t_id number(11), score number(11) ) nologging; truncate table sc; create or replace procedure insert_sc_data is q number(11); begin q:=0; for i in 1..50 loop insert /*+append*/ into sc select rownum+q as s_id, floor(dbms_random.value(0,1000)) as c_id,floor(dbms_random.value(0,10000000)) t_id,floor(dbms_random.value(0,750)) as score from dual connect by level<=1000000; q:=q+1000000; commit; end loop; end insert_sc_data; / call insert_sc_data(); create index idx_s_id on sc(s_id) ; create index idx_t_id on sc(t_id) ; create index idx_c_id on sc(c_id) ; select count(*) from sc; create table teacher ( t_id number(11) , tname varchar2(50) , note varchar2(500) )nologging ; truncate table teacher; create or replace procedure insert_teacher_data is q number(11); begin q:=0; for i in 1..10 loop insert /*+append*/ into teacher select rownum+q as t_id, concat('teacher',rownum+q ) as tname,concat('note',rownum+q ) as note from dual connect by level<=1000000; q:=q+1000000; commit; end loop; end insert_teacher_data; / call insert_teacher_data(); alter table teacher add constraint pk_teacher primary key (t_id); select count(*) from teacher;
原文地址:https://www.cnblogs.com/codechange/p/13083787.html
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解
- 定位地理位置PHP判断员工打卡签到经纬度是否在打卡之内
- PHP APP微信提现接口代码
- thinkPHP5.1框架路由::get、post请求简单用法示例
- Python+Dlib+Opencv实现人脸采集并表情判别功能的代码
- Python爬虫实例——scrapy框架爬取拉勾网招聘信息
- php实现微信企业转账功能
- Laravel框架模型的创建及模型对数据操作示例
- Python环境管理virtualenv&virtualenvwrapper的配置详解
- Matplotlib自定义坐标轴刻度的实现示例
- Python基于time模块表示时间常用方法
- ITK 实现多张图像转成单个nii.gz或mha文件案例
- 一文轻松掌握python语言命名规范规则
- php原生数据库分页的代码实例
- python对一个数向上取整的实例方法
- Laravel框架FormRequest中重写错误处理的方法