-- create database test
-- with owner = postgres
-- encoding = 'UTF8'
-- connection limit = -1;
create table publisher (
id integer primary key,
name_pub varchar(128) not null,
address text not null
);
create table book (
book_id integer primary key,
title text not null ,
isbn varchar(128) not null
);
insert into book values(1, 'thedikfl' , '01236'),(2, 'dima' , '012236'),
(3, 'vova' , '0123633'),
(4, 'tree' , '0123612'),
(5, 'crime' , '201236'),
(6, 'kfmef' , '2301236'),
(7, 'ptyb' , '3301236');
insert into publisher values (1,'dima','moscow'),
(2,'dima2','piter'),
(3,'vova','samara'),
(4,'d','moscow2'),
(5,'di','moscow3'),
(6,'petya','moscow4'),
(7,'vitya','moscow5');
alter table book
add column publisher_id int ;
-- alter table book
-- add constraint publisher_id foreign key(publisher_id ) references publisher(id);
drop table book;
create table book
(
book_id integer primary key,
title text not null ,
isbn varchar(128) not null,
publisher_id integer foreign key(publisher_id ) references publisher(id) not null
)