ID int(11) not null auto_increment,
DEPT_ID int(11) not null,
JOB_ID int(11) not null,
name varchar(20) not null,
CARD_ID varchar(18) not null,
ADDRESS varchar(50) not null,
POST_CODE varchar(50) default null,
TEL varchar(16) default null,
PHONE varchar(11) not null,
QQ_NUM varchar(11) default null,
EMAIL varchar(50) not null,
SEX int(11) not null default '1',
PARTY varchar(10) default null,
BIRTHDAY datetime default null,
RACE varchar(100) default null,
EDUCATION varchar(10) default null,
SPECIALITY varchar(20) default null,
HOBBY varchar(100) default null,
REMARK varchar(500) default null,
CREATE_DATE timestamp not null default current_timestamp,
primary key(id),
key FK_EMP_DEPT(DEPT_ID),
key FK_EMP_JOB(JOB_ID),
constraint FK_EMP_DEPT foreign key(DEPT_ID) references dept_inf (ID),
consistent FK_EMP_JOB foreign key(JOB_ID) references job_inf (ID)
)ENGINE=INNODB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;
这样写会出错,要写成以下这样
CREATE TABLE `employee_inf` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`dept_id` INT(11) NOT NULL,
`job_id` INT(11) NOT NULL,
`name` VARCHAR(20) NOT NULL,
`card_id` VARCHAR(18) NOT NULL,
`address` VARCHAR(50) NOT NULL,
`post_code` VARCHAR(50) DEFAULT NULL,
`tel` VARCHAR(16) DEFAULT NULL,
`phone` VARCHAR(11) NOT NULL,
`qq_num` VARCHAR(10) DEFAULT NULL,
`emall` VARCHAR(50) NOT NULL,
`sex` INT(11) NOT NULL DEFAULT '1',
`party` VARCHAR(10) DEFAULT NULL,
`birthday` DATETIME DEFAULT NULL,
`race` VARCHAR(100) DEFAULT NULL,
`education` VARCHAR(10) DEFAULT NULL,
`speciality` VARCHAR(20) DEFAULT NULL,
`hobby` VARCHAR(100) DEFAULT NULL,
`remark` VARCHAR(500) DEFAULT NULL,
`create_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `fk_emp_dept` (`dept_id`),
KEY `fk_emp_job` (`job_id`),
CONSTRAINT `fk_emp_dept` FOREIGN KEY (`dept_id`) REFERENCES `dept_inf` (`id`),
CONSTRAINT `fk_emp_job` FOREIGN KEY (`job_id`) REFERENCES `job_inf` (`id`)
) ENGINE=INNODB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
原来以为问题出在关键字冲突,后来发现不是的,改成带有单引号的关键字后,发现通过了
所以是标准格式的原因