本帖最后由 zjwilove4 于 2009-10-20 02:27:09 编辑

解决方案 »

  1.   

     StudentInfo(StuNo)
    你没有创建索引!create table StudentInfo 

    StuName varchar(8) not null, 
    StuNo char(6) not null primary key, 
    StuSex char(2) not null, 
    StuAge tinyint not null, 
    StuSeat tinyint not null,
    StuAddress varchar(50),
    constraint PK_StudentInfo_StuSeat primary key (StuNo),
    constraint CK_StudentInfo_StuSex check(StuSex in('男','女'))
    -- constraint CK_StudentInfo_StuNo check(StuNo like 's253[0-9][0-9]'),
    -- constraint CK_StudentInfo_StuAge check(StuAge  < 40 and StuAge > 15), 
    -- constraint CK_StudentInfo_StuSeat check(StuSeat  < 30 and StuSeat > 0)
    -- constraint DF_StudentInfo_StuAddress default '地址不详'
    );
      

  2.   

    外键关联字段要一直 数据要统一 并且量字段要有key
      

  3.   

    呵呵
    CREATE TABLE StudentMarks 

    ExamNo CHAR(7) NOT NULL, 
    StuNo CHAR(6) NOT NULL, 
    WrittenExam TINYINT NOT NULL, 
    LabExam TINYINT NOT NULL, 
    CONSTRAINT PK_StudentMarks_ExamNo PRIMARY KEY (ExamNo)

    CONSTRAINT FK_StudentInfo_StudentMarks_StuNo FOREIGN KEY(StuNo) REFERENCES StudentInfo(StuNo)
    ); constraint PK_StudentMarks_ExamNo primary key ExamNo,->
    constraint PK_StudentMarks_ExamNo primary key (ExamNo),
      

  4.   

    建立PRIMARY KEY时要加括号,注意用INNODB引擎
      

  5.   

    use StudentDB; 
    create table StudentMarks 

    ExamNo char(7) not null primary key, 
    StuNo char(6) not null, 
    WrittenExam tinyint not null, 
    LabExam tinyint not null, 
    constraint FK_StudentInfo_StudentMarks_StuNo foreign key (StuNo) references StudentInfo(StuNo)
    );