首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

建表有关问题求教

2012-05-28 
建表问题求教SQL codecreate database examuse examcreate table Teacher(T_id int primary key,T_title

建表问题求教

SQL code
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);


为什么这个在SQL08下就能顺利执行,在MYSQL下执行会报错呢?
求解。

[解决办法]

SQL code
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);
[解决办法]
SQL code
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; 

热点排行