Criamos um novo BD baseado no banco da aula anterior. No meu caso criei:
CREATE DATABASE bookstore2; Em seguida criamos uma tabela com as seguintes informações:
create table books
(id int unsigned not null auto_increment,
title varchar(255) not null,
date_publish date,
date_aquisition date,
book_comments varchar(255),
price decimal(10,2) not null,
primary key(id));
A propriedade UNIQUE torna os valores de um
campo obrigatóriamente únicos da mesma forma que a
PRIMARY KEY, entretanto diferente da segunda
pode ser utilizado quantas vezes for necessário em uma
tabela. (id int unsigned not null auto_increment,
title varchar(255) not null,
date_publish date,
date_aquisition date,
book_comments varchar(255),
price decimal(10,2) not null,
primary key(id));
No banco de dados criamos uma nova tabela authors que terá uma chave do tipo UNIQUE no campo email.
create table authors
(id int unsigned not null auto_increment,
first_name varchar(255) not null,
last_name varchar(255) not null,
gender char(10) not null,
date_of_birth date not null,
email varchar(255) not null,
unique(email), primar key(id));
Para seguir o roteiro da aula alterei o nome do campo
id da tabela author pelo Workbench com o
comando: (id int unsigned not null auto_increment,
first_name varchar(255) not null,
last_name varchar(255) not null,
gender char(10) not null,
date_of_birth date not null,
email varchar(255) not null,
unique(email), primar key(id));
ALTER TABLE `bookstore2`.`authors` CHANGE COLUMN `id` `author_id` INT(10) UNSIGNED NOT NULL ;
ALTER TABLE `bookstore2`.`authors` DROP PRIMARY KEY;
ALTER TABLE authors ADD CONSTRAINT author_id UNIQUE(author_id);