create table Course
(CourseId char(5),
constraint pkCourseId primary key,
CourseName varchar(30) not null,
Type char(6) constraint fkType foreign key
references CourseType(CourseTypeId),
TeacherId char(3),
constraint fkTeacherId foreign key
references Teacher(TeacherId),
Credit number(2,0)
);create table Score
(ScoreId char(8) constraint pkScoreId primary key,
StudentId char(6) constraint fkStudentId foreign key
references Student(StudentId),
CourseId char(5) constraint fkCourseId foreign key
references Course(CourseId),
Score number(4,1)
);为什么我创建这两个表时总是提示说:此处不允许约束条件说明??

解决方案 »

  1.   


    create table Course 
    (CourseId char(5), 
    CourseName varchar(30) not null, 
    Type char(6),
    TeacherId char(3), 
    Credit number(2,0) 
    ); 
    alter table Course
      add constraint pkCourseId primary key (CourseId)
    alter table Course
      add constraint fkType foreign key (Type)
      references CourseType (CourseTypeId);
    alter table Course
      add constraint fkTeacherId foreign key (TeacherId)
      references Teacher (TeacherId);
      
    create table Score 
    (ScoreId char(8), 
    StudentId char(6), 
    CourseId char(5), 
    Score number(4,1) 
    ); 
    alter table Score
      add constraint pkScoreId primary key (ScoreId)
    alter table Score
      add constraint fkStudentId foreign key (StudentId)
      references Student (StudentId);
    alter table Score
      add constraint fkCourseId foreign key (CourseId)
      references Course (CourseId);
      

  2.   

    create table Course
    (CourseId char(5),  <=====逗号去掉试试
    constraint pkCourseId primary key,
    CourseName varchar(30) not null,
    Type char(6) constraint fkType foreign key
    references CourseType(CourseTypeId),
    TeacherId char(3),  <=====逗号去掉试试
    constraint fkTeacherId foreign key
    references Teacher(TeacherId),
    Credit number(2,0)
    ); 
      

  3.   

    create table Course 
    (CourseId char(5) constraint pkCourseId primary key, 
    CourseName varchar(30) not null, 
    Type char(6),  constraint fkType foreign key(Type) references CourseType(CourseTypeId), 
    TeacherId char(3), constraint fkTeacherId foreign key(TeacherId) references Teacher(TeacherId), 
    Credit number(2,0) 
    ); create table Score 
    (ScoreId char(8) constraint pkScoreId primary key, 
    StudentId char(6), constraint fkStudentId foreign key (StudentId)
    references Student(StudentId), 
    CourseId char(5), constraint fkCourseId foreign key(CourseId)
    references Course(CourseId), 
    Score number(4,1) 
    );
    这样就行
      

  4.   

    可以这样写:
    create table Course
    (CourseId char(5)
    constraint pkCourseId primary key,
    CourseName varchar(30) not null,
    Type char(6),
    TeacherId char(3),
    Credit number(2,0),
    constraint fkType foreign key(Type) references CourseType(CourseTypeId),
    constraint fkTeacherId foreign key(TeacherId) references Teacher(TeacherId)
    );create table Score 
    (ScoreId char(8) constraint pkScoreId primary key, 
    StudentId char(6), 
    CourseId char(5), 
    Score number(4,1),
    constraint fkStudentId foreign key(StudentId) references Student(StudentId), 
    constraint fkCourseId foreign key(CourseId) references Course(CourseId)
    );