create table class(
class_id char(6) primary key,dept_id char(4) not null,coll_id char(2),
class_name varchar(6) not null,
constraint class_fk1 foreign key(dept_id) references dept(dept_id),
constraint class_fk2 foreign key(coll_id) references college(coll_id)
);建一个class表,constraint ... references 具体是什么意思,不太明白,谢谢大侠的赐教。

解决方案 »

  1.   

    写SQL语句语句是固定,没什么大的变化create table class(
    class_id char(6) primary key,
    dept_id char(4) not null,
    coll_id char(2),
    class_name varchar(6) not null,
    constraint class_fk1 foreign key(dept_id) references dept(dept_id),
    constraint class_fk2 foreign key(coll_id) references college(coll_id)
    );constraint ... references 具体是什么意思
    外键约束。《数据库系统概论(第四版)》 王珊 萨师煊   高等教育出版社 (掌握基础知识和概念) 然后再粗略浏览一遍MYSQL的官方手册。(方便以后查找,避免类似于考试的时候,给你本政治书也不知道答案在第几章,第几页)MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html