CREATE TABLE `tbl_dept`(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`deptName` VARCHAR(30) DEFAULT NULL,
`locAdd` VARCHAR(40) DEFAULT NULL,
PRIMARY KEY (`id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `tbl_emp`(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(30) DEFAULT NULL,
`deptId` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_dept_id` (`deptId`)
#CONSTRAINT `fk_dept_id` FOREIGN KEY (`deptId`) REFERENCES `tbl_dept` (`id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into tbl_dept(deptName,locAdd) VALUES('RD',11);
insert into tbl_dept(deptName,locAdd) VALUES('HR',12);
insert into tbl_dept(deptName,locAdd) VALUES('MK',13);
insert into tbl_dept(deptName,locAdd) VALUES('MIS',14);
insert into tbl_dept(deptName,locAdd) VALUES('FD',15);
insert into tbl_emp(name,deptId) VALUES('Z3',1);
insert into tbl_emp(name,deptId) VALUES('Z4',1);
insert into tbl_emp(name,deptId) VALUES('Z5',1);
insert into tbl_emp(name,deptId) VALUES('w5',2);
insert into tbl_emp(name,deptId) VALUES('w6',2);
insert into tbl_emp(name,deptId) VALUES('s7',3);
insert into tbl_emp(name,deptId) VALUES('s8',4);
insert into tbl_emp(name,deptId) VALUES('s9',51);
create table if not exists `article`(
`id` INT(10) unsigned NOT NULL primary key auto_increment,
`article_id` INT(10) unsigned NOT NULL,
`category_id` INT(10) unsigned NOT NULL,
`views` INT(10) unsigned NOT NULL,
`comments` INT(10) unsigned NOT NULL,
`title` VARCHAR(255) NOT NULL,
`content` TEXT NOT NULL
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into `article` (`article_id`, `category_id`,`views`,`comments`,`title`,`content`) values
(1,1,1,1,'1','1'),
(2,2,2,2,'2','2'),
(3,3,3,3,'3','3');
create table if not exists `class`(
`clsid` INT(10) unsigned NOT NULL auto_increment,
`card` INT(10) unsigned NOT NULL,
primary key(`clsid`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
create table if not exists `book`(
`bookid` INT(10) unsigned NOT NULL auto_increment,
`card` INT(10) unsigned NOT NULL,
primary key(`bookid`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into class(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
insert into book(card) values(floor(1+(RAND()*20)));
create table if not exists `phone`(
`phoneid` INT(10) unsigned NOT NULL auto_increment,
`card` INT(10) unsigned NOT NULL,
primary key(`phoneid`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
insert into phone(card) values(floor(1+(RAND()*20)));
create table if not exists `staffs`(
`id` INT primary key auto_increment,
`name` varchar(24) NOT NULL default,
`age` INT NOT NULL default 0,
`pos` varchar(20) NOT NULL default,
`add_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into staffs(name,age,pos,add_time) values ('z3',22,'manager',NOW());
insert into staffs(name,age,pos,add_time) values ('july',23,'dex',NOW());
insert into staffs(name,age,pos,add_time) values ('2000',23,'manager',NOW());
alter table staffs add index idx_staffs_nap(name,age,pos);
CREATE TABLE `tbl_user`(
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(30) DEFAULT NULL,
`age` INT(11) DEFAULT NULL,
`email` VARCHAR(20) DEFAULT NULL,
PRIMARY KEY (`id`)
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into tbl_user(name,age,email) values ('1aa1',21,'[email protected]');
insert into tbl_user(name,age,email) values ('2aa2',222,'[email protected]');
insert into tbl_user(name,age,email) values ('3aa3',265,'[email protected]');
insert into tbl_user(name,age,email) values ('4aa4',21,'[email protected]');
CREATE TABLE `tblA`(
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`age` INT(11) DEFAULT NULL,
`birth` timestamp not NULL
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into tblA(age,birth) values (22,now());
insert into tblA(age,birth) values (23,now());
insert into tblA(age,birth) values (24,now());
create index idx_A_ageBirth on tblA(age,birth);
select * from tblA;
create database bigData;
use bigData;
create table dept(
`id` INT unsigned primary key NOT NULL AUTO_INCREMENT,
`deptno` mediumint unsigned not NULL DEFAULT 0,
`dname` varchar(20) not null default "",
`loc` VARCHAR(13) not NULL DEFAULT ""
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
create table emp(
id int unsigned primary key not null auto_increment,
empno int unsigned not null default 0,
ename varchar(20) not null default "",
job varchar(20) not null default "",
mgr int unsigned not null default 0,
hiredate date not null,
sal decimal(7,2) not null,
comm decimal(7,2) not null,
deptno int unsigned not null default 0
)ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
delimiter $$
create function rand_string(n int) returns varchar(255)
begin
declare chars_str varchar(100) default 'qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJMIKOLP';
declare return_str varchar(255) default '';
declare i int default 0;
while i < n do
set return_str = concat(return_str,substring(chars_str,floor(1+rand()*52),1));
set i = i + 1;
end while;
return return_str;
end $$
delimiter $$
create function rand_num() returns int(5)
begin
declare i int default 0;
set i = floor(100 + rand()*10);
return i;
end$$
delimiter $$
create procedure insert_emp(in start int(10),in max_num int(10))
begin
declare i int default 0;
set autocommit = 0;
repeat
set i = i + 1;
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)
values
((start+i),rand_string(6),'saleman',00001,curdate(),2000,400,rand_num());
until i = max_num
end repeat;
commit;
end $$
delimiter $$
create procedure insert_dept(in start int(10),in max_num int(10))
begin
declare i int default 0;
set autocommit = 0;
repeat
set i = i + 1;
insert into dept(deptno,dname,loc)
values((start+i),rand_string(10),rand_string(8));
until i = max_num
end repeat;
commit;
end $$
delimiter ;
call insert_dept(100,10);
delimiter ;
call insert_emp(100001,500000);
select * from emp group by id%10 limit 150000;
select * from emp group by id%20 order by 5;