drop table if exists devolucao; drop table if exists aluguer; drop table if exists copia; drop table if exists filme_realizador; drop table if exists filme_actor; drop table if exists filme; drop table if exists socio; drop table if exists genero; drop table if exists editora; drop table if exists actor; drop table if exists realizador; create table socio(num_socio INTEGER PRIMARY KEY AUTOINCREMENT, nome_socio CHAR(35) not null unique, bi_socio INTEGER not null unique, data_nsc_socio date not null, morada_socio CHAR(35) not null, tlf_socio CHAR(15) not null, sexo_socio CHAR(1) not null CHECK ( sexo_socio IN ( 'F' , 'M' ) )); create table genero(cod_genero INTEGER PRIMARY KEY AUTOINCREMENT, nome_genero CHAR(25) NOT NULL UNIQUE); create table editora(cod_editora INTEGER PRIMARY KEY AUTOINCREMENT, nome_editora char(35) not null unique); create table actor(cod_actor INTEGER PRIMARY KEY AUTOINCREMENT, nome_actor char(35) not null unique); create table realizador(cod_realizador INTEGER PRIMARY KEY AUTOINCREMENT, nome_realizador char(35) not null unique); create table filme(cod_filme INTEGER PRIMARY KEY AUTOINCREMENT, nome_filme char(35) not null, ano_filme integer not null, preco_dia_filme real not null, dias_sem_multa_filme integer not null, multa_dia_filme real not null, cod_genero integer not null, cod_editora integer not null, foreign key (cod_genero) references genero, foreign key (cod_editora) references editora); create table filme_actor(cod_filme integer not null, cod_actor integer not null, primary key (cod_filme, cod_actor), foreign key (cod_filme) references filme, foreign key (cod_actor) references actor); create table filme_realizador(cod_filme integer not null, cod_realizador integer not null, primary key (cod_filme, cod_realizador), foreign key (cod_filme) references filme, foreign key (cod_realizador) references realizador); create table copia(cod_filme integer not null, num_copia integer not null, primary key (cod_filme, num_copia), foreign key (cod_filme) references filme); create table aluguer(cod_filme integer not null, num_copia integer not null, data_aluguer date not null, num_socio integer not null, primary key (cod_filme, num_copia, data_aluguer), foreign key (cod_filme, num_copia) references copia, foreign key (num_socio) references socio ); create table devolucao(cod_filme integer not null, num_copia integer not null, data_aluguer date not null, data_devolucao date not null, estado_devolucao char(20) not null, primary key (cod_filme, num_copia, data_aluguer), foreign key (cod_filme, num_copia, data_aluguer) references aluguer);