日期:2014-05-16 浏览次数:20800 次
create database exam; use exam; create table Teacher (T_id int primary key, T_title varchar(255) not null, T_pwd varchar(255) not null ); create table Radio (r_id int primary key, T_id int foreign key (T_id) references Teacher(T_id) on update cascade on delete cascade, r_desc varchar(255) not null, option_A varchar(255) not null, option_B varchar(255) not null, option_C varchar(255) not null, option_D varchar(255) not null, r_true char not null );
create table Radio (r_id int primary key, T_id int , r_desc varchar(255) not null, option_A varchar(255) not null, option_B varchar(255) not null, option_C varchar(255) not null, option_D varchar(255) not null, r_true char not null, foreign key (T_id) references Teacher(T_id) on update cascade on delete cascade );
------解决方案--------------------
CREATE TABLE `Radio` ( `r_id` int(11) NOT NULL, `T_id` int(11) DEFAULT NULL, `r_desc` varchar(255) NOT NULL, `option_A` varchar(255) NOT NULL, `option_B` varchar(255) NOT NULL, `option_C` varchar(255) NOT NULL, `option_D` varchar(255) NOT NULL, `r_true` char(1) NOT NULL, PRIMARY KEY (`r_id`), KEY `T_id` (`T_id`), CONSTRAINT `Radio_ibfk_1` FOREIGN KEY (`T_id`) REFERENCES `Teacher` (`T_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;