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 CHARACTER SET = 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);
### P31
* article
CREATE TABLE IF NOT EXISTS article
(
id
INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
author\_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
VARBINARY(255) NOT NULL,
content
TEXT NOT NULL
);
insert into article
(author_id,category_id,views,comments,title,content) values
(1,1,1,1,‘1’,‘1’),
(2,2,2,2,‘2’,‘2’),
(1,1,3,3,‘3’,‘3’);
### P32
* class
* book
CREATE TABLE IF NOT EXISTS class
(
id
INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
card
INT (10) UNSIGNED NOT NULL
);
CREATE TABLE IF NOT EXISTS book
(
bookid
INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
card
INT (10) UNSIGNED NOT NULL
);
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)));
### P33
* phone
CREATE TABLE IF NOT EXISTS phone
(
phoneid
INT(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
card
INT (10) UNSIGNED NOT NULL
)ENGINE = INNODB;
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)));
### P34
* staffs
CREATE TABLE staffs(
id INT PRIMARY KEY AUTO_INCREMENT,
name
VARCHAR(24)NOT NULL DEFAULT’’ COMMENT’姓名’,
age
INT NOT NULL DEFAULT 0 COMMENT’年龄’,
pos
VARCHAR(20) NOT NULL DEFAULT’’ COMMENT’职位’,
add\_time
TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT’入职时间’
)CHARSET utf8 COMMENT’员工记录表’;
insert into staffs(NAME,age,pos,add_time) values(‘z3’,22,‘manager’,NOW());
insert into staffs(NAME,age,pos,add_time) values(‘July’,23,‘dev’,NOW());
insert into staffs(NAME,age,pos,add_time) values(‘2000’,23,‘dev’,NOW());
### P40
* tbl\_user
CREATE TABLE tbl_user(
id
INT(11) NOT NULL AUTO_INCREMENT,
name
VARCHAR(20) 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,‘b@163.com’);
insert into tbl_user(NAME,age,email) values(‘2aa2’,222,‘a@163.com’);
insert into tbl_user(NAME,age,email) values(‘3aa3’,265,‘c@163.com’);
insert into tbl_user(NAME,age,email) values(‘4aa4’,21,‘d@163.com’);
### P44
* test03
create table test03(
id int primary key not null auto_increment,
c1 char(10),
c2 char(10),
c3 char(10),
c4 char(10),
c5 char(10)
);
insert into test03(c1,c2,c3,c4,c5) values(‘a1’,‘a2’,‘a3’,‘a4’,‘a5’);
insert into test03(c1,c2,c3,c4,c5) values(‘b1’,‘b2’,‘b3’,‘b4’,‘b5’);
insert into test03(c1,c2,c3,c4,c5) values(‘c1’,‘c2’,‘c3’,‘c4’,‘c5’);
insert into test03(c1,c2,c3,c4,c5) values(‘d1’,‘d2’,‘d3’,‘d4’,‘d5’);
insert into test03(c1,c2,c3,c4,c5) values(‘e1’,‘e2’,‘e3’,‘e4’,‘e5’);
### P48
* tblA
create table tblA(
age int,
birth timestamp not null
);
insert into tblA(age,birth) values(22,now());
insert into tblA(age,birth) values(23,now());
insert into tblA(age,birth) values(24,now());
### P50
create table dept(
id int unsigned primary key auto_increment,
deptno mediumint unsigned not null default 0,
dname varchar(20) not null default “”,
loc varchar(13) not null default “”
)engine=innodb default charset=GBK;
CREATE TABLE emp(
id int unsigned primary key auto_increment,
empno mediumint unsigned not null default 0,
ename varchar(20) not null default “”,
job varchar(9) not null default “”,
mgr mediumint unsigned not null default 0,
hiredate date not null,
sal decimal(7,2) not null,
comm decimal(7,2) not null,
deptno mediumint unsigned not null default 0
)ENGINE=INNODB DEFAULT CHARSET=GBK;
//函数
delimiter KaTeX parse error: Undefined control sequence: \* at position 311: …,floor(1+rand()\̲*̲52),1)); set i=…
//函数
delimiter KaTeX parse error: Undefined control sequence: \* at position 97: …loor(100+rand()\̲*̲10); return i; …
//存储过程
delimiter
c
r
e
a
t
e
p
r
o
c
e
d
u
r
e
i
n
s
e
r
t
e
m
p
(
i
n
s
t
a
r
t
i
n
t
(
10
)
,
i
n
m
a
x
n
u
m
i
n
t
(
10
)
)
b
e
g
i
n
d
e
c
l
a
r
e
i
i
n
t
d
e
f
a
u
l
t
0
;
s
e
t
a
u
t
o
c
o
m
m
i
t
=
0
;
r
e
p
e
a
t
s
e
t
i
=
i
+
1
;
i
n
s
e
r
t
i
n
t
o
e
m
p
(
e
m
p
n
o
,
e
n
a
m
e
,
j
o
b
,
m
g
r
,
h
i
r
e
d
a
t
e
,
s
a
l
,
c
o
m
m
,
d
e
p
t
n
o
)
v
a
l
u
e
s
(
(
s
t
a
r
t
+
i
)
,
r
a
n
s
t
r
i
n
g
(
6
)
,
′
s
a
l
e
s
m
a
n
′
,
0001
,
c
u
r
d
a
t
e
(
)
,
2000
,
400
,
r
a
n
d
n
u
m
(
)
)
;
u
n
t
i
l
i
=
m
a
x
n
u
m
e
n
d
r
e
p
e
a
t
;
c
o
m
m
i
t
;
e
n
d
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),ran_string(6),'salesman',0001,curdate(),2000,400,rand_num()); until i=max_num end repeat; commit; end
createprocedureinsertemp(instartint(10),inmaxnumint(10))begindeclareiintdefault0;setautocommit=0;repeatseti=i+1;insertintoemp(empno,ename,job,mgr,hiredate,sal,comm,deptno)values((start+i),ranstring(6),′salesman′,0001,curdate(),2000,400,randnum());untili=maxnumendrepeat;commit;end
//存储过程
delimiter
c
r
e
a
t
e
p
r
o
c
e
d
u
r
e
i
n
s
e
r
t
d
e
p
t
(
i
n
s
t
a
r
t
i
n
t
(
10
)
,
i
n
m
a
x
n
u
m
i
n
t
(
10
)
)
b
e
g
i
n
d
e
c
l
a
r
e
i
i
n
t
d
e
f
a
u
l
t
0
;
s
e
t
a
u
t
o
c
o
m
m
i
t
=
0
;
r
e
p
e
a
t
s
e
t
i
=
i
+
1
;
i
n
s
e
r
t
i
n
t
o
d
e
p
t
(
d
e
p
t
n
o
,
d
n
a
m
e
,
l
o
c
)
v
a
l
u
e
s
(
(
s
t
a
r
t
+
i
)
,
r
a
n
s
t
r
i
n
g
(
10
)
,
r
a
n
s
t
r
i
n
g
(
8
)
)
;
u
n
t
i
l
i
=
m
a
x
n
u
m
e
n
d
r
e
p
e
a
t
;
c
o
m
m
i
t
;
e
n
d
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),ran_string(10),ran_string(8)); until i=max_num end repeat; commit; end
createprocedureinsertdept(instartint(10),inmaxnumint(10))begindeclareiintdefault0;setautocommit=0;repeatseti=i+1;insertintodept(deptno,dname,loc)values((start+i),ranstring(10),ranstring(8));untili=maxnumendrepeat;commit;end
### P54
* mylock