Define foreign key between tables

Asked

Viewed 30 times

0

I need to make a Mysql database, Escola, with entities aluno, professor and disciplina, linked via foreign key.

I made mine script, but it’s making a mistake. Could you help me? Follow what I did:

CREATE DATABASE ESCOLA
DEFAULT CHARACTER SET uft8
DEFAULT COLLATE utf8_general_ci;
use escola;

CREATE TABLE professor(
  nome varchar(50) not null ,
  idade int(2) ,
  salario float(4,2) ,
  cod_prof int(10) not null,
  primary key cod_prof
)CHARSET=utf8

CREATE TABLE aluno(
  nome varchar(50) not null,
  id int(10) not null AUTO_INCREMENT,
  cod_aluno int(10) not null,
  cod_dis int(10) not null,
  PRIMARY KEY (cod_aluno)
  CONSTRAINT cod_dis FOREIGN KEY (cod_dis) REFERENCES disciplina(cod_dis)
)CHARSET=utf8


CREATE TABLE disciplina(
  nome varchar(50) not null,
  carga_horaria char(2) ,
  cod_prof int(10) not null,
  cod_dis int(10) not null,
  FOREIGN KEY (cod_prof) REFERENCES professor(cod_prof)
  PRIMARY KEY (cod_dis)
)CHARSET=utf8

Error Code: 1064. You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near ')CHARSET=utf8' at line 7

  • Missed to put the error...

  • I believe you do not have this = in CHARSET=utf8. But you no longer set for the whole bank?

  • I’m starting.. I saw in some videos of the internet that with these codes I can put accent in the words.

  • student makes reference to discipline , created after, Since this.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.