/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 2015/5/20 14:45:38 */
/*==============================================================*/
drop table if exists sname;
drop table if exists 专业方向;
drop table if exists 教师;
drop table if exists 班级;
drop table if exists 课程;
drop table if exists 课程安排;
drop table if exists 选课;
drop table if exists 院系;
/*==============================================================*/
/* Table: sname */
/*==============================================================*/
create table sname
(
sno national char(20) not null,
classID int not null,
name national char(20) not null,
ssex national char(2) not null,
primary key (sno)
);
/*==============================================================*/
/* Table: 专业方向 */
/*==============================================================*/
create table 专业方向
(
major int not null,
departID int not null,
majorname national varchar(20) not null,
primary key (major)
);
/*==============================================================*/
/* Table: 教师 */
/*==============================================================*/
(!!!!]显示有错误)create table 教师
(
"job number" int not null,
"teacher name" national varchar(50) not null,
title national varchar(50) not null,
intur text,
primary key ("job number")
);
/*==============================================================*/
/* Table: 班级 */
/*==============================================================*/
create table 班级
(
classID int not null,
major int not null,
classname national varchar(20) not null,
primary key (classID)
);
/*==============================================================*/
/* Table: 课程 */
/*==============================================================*/
create table 课程
(
coursename national varchar(20) not null,
credit float not null,
courseID int not null,
primary key (courseID)
);
/*==============================================================*/
/* Table: 课程安排 */
/*==============================================================*/
(!!!!显示有错误)create table 课程安排
(
arrange national varchar(255) not null,
arrangeID int not null,
courseID int not null,
"job number" int not null,
primary key (arrangeID)
);
/*==============================================================*/
/* Table: 选课 */
/*==============================================================*/
create table 选课
(
sno national char(20) not null,
arrangeID int not null,
selsecttime datetime not null,
selsctend tinyint,
primary key (sno, arrangeID)
);
/*==============================================================*/
/* Table: 院系 */
/*==============================================================*/
(!!!!显示有错误)create table 院系
(
departID int not null,
departname VBIN50 not null,
primary key (departID)
);
alter table sname add constraint FK_Relationship_1 foreign key (classID)
references 班级 (classID) on delete restrict on update restrict;
alter table 专业方向 add constraint FK_Relationship_3 foreign key (departID)
references 院系 (departID) on delete restrict on update restrict;
alter table 班级 add constraint FK_Relationship_2 foreign key (major)
references 专业方向 (major) on delete restrict on update restrict;
alter table 课程安排 add constraint FK_Relationship_4 foreign key ("job number")
references 教师 ("job number") on delete restrict on update restrict;
alter table 课程安排 add constraint FK_Relationship_5 foreign key (courseID)
references 课程 (courseID) on delete restrict on update restrict;
alter table 选课 add constraint FK_选课 foreign key (sno)
references sname (sno) on delete restrict on update restrict;
alter table 选课 add constraint FK_选课2 foreign key (arrangeID)
references 课程安排 (arrangeID) on delete restrict on update restrict;
------解决思路----------------------
MYSQL?
------解决思路----------------------
之前没试过一张表可以这样给两个主键,其次,您的类型报错了。
------解决思路----------------------
抱歉,是我看错了,原来是MySQL。没用过,所以无能为力。
------解决思路----------------------
我也不清楚,你给中文的表名都加上 单撇号试下 ` 不是单引号
------解决思路----------------------
去 MySQL 版问问吧
------解决思路----------------------
把错误语句帖出来看看呢,直接看太累了。实在不行就一条一条执行,这样比较好找错误,揉在一起反倒不好
------解决思路----------------------
"job number"
=>
job_number