Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 我正试图用sql实现这段代码,但还是遇到了一个错误,我真的不知道为什么_Mysql_Sql - Fatal编程技术网

Mysql 我正试图用sql实现这段代码,但还是遇到了一个错误,我真的不知道为什么

Mysql 我正试图用sql实现这段代码,但还是遇到了一个错误,我真的不知道为什么,mysql,sql,Mysql,Sql,您的代码中存在多个问题: 很少有语法是不正确的 mysql中应该使用int(6)而不是number(6) varchar必须具有数据大小。-varchar(200) 必须在创建引用表后创建外键 示例模式中正确语法的几个示例如下: create table student ( student_ID number(6) primary key, student_name varchar (25) unique , address varchar , sex char, manager_ID n

您的代码中存在多个问题:

  • 很少有语法是不正确的
  • mysql中应该使用
    int(6)
    而不是
    number(6)
  • varchar
    必须具有数据大小。-<代码>varchar(200)
  • 必须在创建引用表后创建外键
示例模式中正确语法的几个示例如下:

create table student (
student_ID number(6) primary key,
student_name varchar (25) unique ,
address varchar ,
sex char, 
manager_ID number(6) REFERENCES maneger (manager_ID) , 
birth_date date NOT NULL 
);
create table Classes (
class_ID number(6) primary key ,
student_ID number (6)REFERENCES student (student_ID), FOREIGN KEY
);
create table manager (
manager_ID number (6) primary key,
manager_name char ,
address varchar,
Teacher_ID number (6) FOREIGN KEY, REFERENCES teacher (Teacher_ID),
sex char
);
create table teacher (
Teacher_ID number (6), primary key,
teacher_name varchar, 
address varchar , 
class_ID number (6)  FOREIGN KEY REFERENCES Classes (class_ID) ,
subject_name varchar REFERENCES subject (subject_name)
);
create table subject (
subject_name varchar  primary key,
marks number 
);
create learn (
student_ID number (6) REFERENCES student (student_ID), 
subject_name varchar REFERENCES subject (subject_name) , 
constraint PK_student primary key (student_ID,subject_name)
);
create table teach (
student_ID number (6)REFERENCES student (student_ID) , 
Teacher_ID number (6) REFERENCES teacher (Teacher_ID),
constraint PK_teach primary key (student_ID,Teacher_ID)
);

具有正确的表定义。请使用
alter table\u name add constraint添加外键…

如果您告诉我们错误,则会有所帮助。您需要先创建引用表,然后才能在student中正确引用表和拼写管理器。
create table student 
(
    student_ID int(6) primary key,
    student_name varchar (25) unique ,
    address varchar(200) ,
    sex char(10), 
    manager_ID int(6),
    birth_date date NOT NULL 
);

create table Classes 
(
    class_ID int(6) primary key ,
    student_ID int (6) references student (student_ID) 
);