尚硅谷 -夏磊高级8个sql-建表语句
create table t_dept(
id int(11) not null auto_increment,
deptName varchar(30) default null,
address varchar(40) default null,
primary key(id)
)engine=innodb auto_increment=1 default charset=utf8;
create table t_emp(
id int(11) not null auto_increment,
name varchar(20) default null,
age int(3) default null,
deptld int(11) default null,
empno int not null,
primary key(id),
key idx_dept_id(deptld)
#constraint fk_dept_id foreign key(deptld) references t_dept(id)
)engine=innodb auto_increment=1 default charset=utf8;
insert into t_dept(deptName, address) values('华山', '华山');
insert into t_dept(deptName, address) values('丐帮', '洛阳');
insert into t_dept(deptName, address) values('峨眉', '峨眉山');
insert into t_dept(deptName, address) values('武当', '武当山');
insert into t_dept(deptName, address) values('明教', '光明顶');
insert into t_dept(deptName, address) values('少林', '少林寺');
insert into t_emp(name, age, deptld, empno) values('风清扬', 90, 1, 100001);
insert into t_emp(name, age, deptld, empno) values('岳不群', 50, 1, 100002);
insert into t_emp(name, age, deptld, empno) values('令狐冲', 24, 1, 100003);
insert into t_emp(name, age, deptld, empno) values('洪七公', 70, 2, 100004);
insert into t_emp(name, age, deptld, empno) values('乔峰', 35, 2, 100005);
insert into t_emp(name, age, deptld, empno) values('灭绝师太', 70, 3, 100006);
insert into t_emp(name, age, deptld, empno) values('周芷若', 20, 3, 100007);
insert into t_emp(name, age, deptld, empno) values('张三丰', 100, 4, 100008);
insert into t_emp(name, age, deptld, empno) values('张无忌', 25, 5, 100009);
insert into t_emp(name, age, deptld, empno) values('韦小宝', 18, null, 100010);