SQL database structure of a bookstore [closed]

-1

I need to write and populate a MySQL database on controlling a bookstore. This involves: 3 tables: | publisher | book | author |

The 'publisher' table should have: id, name, city, state, country.

The 'book' table should have: ISBN, name, year.

The 'author' table should have: cpf, date of birth, 1st name, 2nd name, country.

For the creation of the database and of each table I am not having problems. The problem is that I need to organize these tables so that they correlate, for example, when I want to delete all of a book's records from a single author (which would involve two different tables for a single command).

I read about it and I think it's about "joins", but I do not even know where to start.

    
asked by anonymous 17.10.2016 / 02:53

1 answer

2

Create the editora table after the autor table, when you create the livro table, make the relationship between them. EX:

create table editora
(
   id integer(11) primary key NOT NULL,
   nome varchar(50) NOT NULL,
   endereco varchar(50) NOT NULL
);

create table autor 
(
  id integer(11) primary key NOT NULL,
  nome varchar(50) NOT NULL,
  idade integer(3) NOT NULL
);

create table livro 
(
  id integer(11) primary key NOT NULL,
  fk_autor integer(11) NOT NULL,
  fk_editora integer(11) NULL,
  titulo varchar(50) NOT NULL,
  valor float NOT NULL,
  foreign key(fk_autor) references autor(id),
  foreign key(fk_editora) references editora(id)
);
    
17.10.2016 / 03:32