-- -------------------约束(外键)--------------- 准备数据createtable dept(
id intauto_incrementcomment'ID'primarykey,
name varchar(50)notnullcomment'部门名称')comment'部门表';insertinto dept(id, name)VALUES(1,'研发部'),(2,'市场部'),(3,'财务部'),(4,'销售部'),(5,'总经办');
createtable emp(
id intauto_incrementcomment'ID'primarykey,
name varchar(50)notnullcomment'姓名',
age intcomment'年龄',
job varchar(20)comment'职位',
salary intcomment'薪资',
entrydate datecomment'入职时间',
managerid intcomment'直属领导ID',
dept_id intcomment'部门ID')comment'员工表';insertinto emp (id, name, age, job, salary, entrydate, managerid, dept_id)VALUES(1,'金庸',66,'总裁',2000,'2000-01-01',null,5),(2,'张无忌',20,'项目经理',12500,'2005-12-05',1,1),(3,'杨逍',33,'开发',8400,'2000-11-03',2,1),(4,'韦一笑',48,'开发',11000,'2002-02-05',2,1),(5,'常遇春',43,'开发',10500,'2004-09-07',3,1),(6,'小昭',19,'程序员鼓励师',6600,'2004-10-12',2,1);