CREATE TABLE album ( artist_id character varying(32) NOT NULL, album_id character varying(32) NOT NULL, album_name character varying(255), album_year integer ); CREATE TABLE album_song ( artist_id character varying(32) NOT NULL, album_id character varying(32) NOT NULL, song_id character varying(32) NOT NULL, as_track integer ); CREATE TABLE artist ( artist_id character varying(32) NOT NULL, artist_name character varying(255) ); -- CREATE VIEW albums_artistas AS SELECT a.artist_name, b.album_name FROM (album b JOIN artist a ON (((b.artist_id)::text = (a.artist_id)::text))) ORDER BY a.artist_name, b.album_name; CREATE TABLE cd ( cd_id character varying(255) NOT NULL ); CREATE TABLE file ( artist_id character varying(32) NOT NULL, album_id character varying(32) NOT NULL, song_id character varying(32) NOT NULL, cd_id character varying(32) NOT NULL, file_id character varying(32) NOT NULL, file_name character varying(8000), sample_rate integer, bps double precision, "time" double precision, bits_per_sample integer, channels integer, size integer ); CREATE VIEW cd_album AS SELECT DISTINCT f.cd_id, a.artist_name, b.album_name FROM ((artist a JOIN album b ON (((a.artist_id)::text = (b.artist_id)::text))) JOIN file f ON ((((b.album_id)::text = (f.album_id)::text) AND ((b.artist_id)::text = (f.artist_id)::text)))) ORDER BY f.cd_id, a.artist_name, b.album_name; CREATE TABLE song ( song_id character varying(32) NOT NULL, song_name character varying(255) ); CREATE VIEW edicion AS SELECT f.cd_id, f.file_id, f.file_name, a.artist_name, b.album_name, b.album_year, ab.as_track, s.song_name FROM ((((file f JOIN artist a ON (((f.artist_id)::text = (a.artist_id)::text))) JOIN album b ON ((((f.artist_id)::text = (b.artist_id)::text) AND ((f.album_id)::text = (b.album_id)::text)))) JOIN album_song ab ON (((((f.artist_id)::text = (ab.artist_id)::text) AND ((f.album_id)::text = (ab.album_id)::text)) AND ((f.song_id)::text = (ab.song_id)::text)))) JOIN song s ON (((f.song_id)::text = (s.song_id)::text))); CREATE VIEW vista_cd AS SELECT f.cd_id, f.file_name, a.artist_name, b.album_name, ab.as_track, s.song_name FROM ((((file f JOIN artist a ON (((f.artist_id)::text = (a.artist_id)::text))) JOIN album b ON ((((f.artist_id)::text = (b.artist_id)::text) AND ((f.album_id)::text = (b.album_id)::text)))) JOIN album_song ab ON (((((f.artist_id)::text = (ab.artist_id)::text) AND ((f.album_id)::text = (ab.album_id)::text)) AND ((f.song_id)::text = (ab.song_id)::text)))) JOIN song s ON (((f.song_id)::text = (s.song_id)::text)));