------------------------------------------------------------- -- cs3200 Database design -- v180121 ------------------------------------------------------------- ------------------------- -- Drop tables if they already exist ------------------------- DO $$ BEGIN IF EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'r') THEN DROP Table R; END IF; IF EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 's') THEN DROP Table S; END IF; IF EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 't') THEN DROP Table T; END IF; IF EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 't2') THEN DROP Table T2; END IF; IF EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'U') THEN DROP Table U; END IF; ------------------------- -- Create tables ------------------------- create table R (a int PRIMARY KEY); create table S (a int PRIMARY KEY); create table T (a int PRIMARY KEY); create table T2 (a int PRIMARY KEY); create table U (a int PRIMARY KEY); --------------------------- -- Populate the tables --------------------------- insert into R values (1); insert into R values (2); insert into S values (1); insert into T values (2); insert into U values (2); insert into U values (3); insert into U values (4); END $$