You are on page 1of 3

DDL statements: -- Parse::SQL::Dia version 0.16 -- Documentation http://search.cpan.org/dist/Parse-Dia-SQL/ -- Environment Perl 5.012000, C:\strawberry\perl\bin\perl.

exe -- Architecture MSWin32-x86-multi-thread -- Target Database postgres -- Input file mid_term.dia -- Generated at Fri Mar 1 15:41:43 2013 -- Typemap for postgres not found in input file --Creates tables, sets and defines field parameters create table tbl_NRGNR_Locations ( LocationID varchar (35) not null, LocationDescript varchar (255) , UTMX numeric (15,5) , UTMY numeric (15,5) , Habitat varchar (35) , HabitatDescription varchar (255) , constraint pk_tbl_NRGNR_Locations primary key (LocationID) ) ; create table tbl_NRGNR_data ( RecID varchar (5) not null, LocationID varchar (35) , EventID varchar (35) , Category varchar (2) , Protocol varchar (255) , SpeciesID varchar (10) , TimeofDay varchar (20) , Number integer , constraint pk_tbl_NRGNR_data primary key (RecID) ) ; create table tbl_NRGNR_species ( SpeciesID varchar (10) not null, CategoryID varchar (6) , FullLatinName varchar (75) , CommonName varchar (75) , constraint pk_tbl_NRGNR_species primary key (SpeciesID) ) ; create table tbl_NRGNR_Events ( EventID varchar (35) not null, Year integer , constraint pk_tbl_NRGNR_Events primary key (EventID) ) ; --sets relationships between tables alter table tbl_NRGNR_data add constraint LocationsHaveData foreign key (LocationID) references tbl_NRGNR_Locations (LocationID) ; alter table tbl_NRGNR_data add constraint DataHasSpecies

foreign key (SpeciesID) references tbl_NRGNR_species (SpeciesID) ; alter table tbl_NRGNR_data add constraint EventsHaveData foreign key (EventID) references tbl_NRGNR_Events (EventID) ; DML statements: --Populating NRGNR tables with data from steamtown.cnr.ncsu.edu. (this data was exported from MS Access as a CSV file) --March 1, 2013 COPY tbl_nrgnr_locations FROM 'c:/gis/tblLocations.txt' DELIMITERS ',' CSV; COPY tbl_nrgnr_events FROM 'c:/gis/tblEvents.txt' DELIMITERS ',' CSV; COPY tbl_nrgnr_species FROM 'c:/gis /lu_species.txt' DELIMITERS ',' CSV; COPY tbl_nrgnr_data FROM 'c:/gis/tbl_data.txt' DELIMITERS ',' CSV; Misc. SQL statements: --used to find all different types of spellings of the entries for the habitats data in the locations table select l.locationid, l.locationDescript, l.habitatDescription, l.habitat from tbl_nrgnr_locations As l where l.habitat != 'Aquatic' and l.habitat != 'Terrestrial' and l.habitat != 'Aquatic and Terrestrial' --Updates habitat field entries to a consistent format (fixes for lower case) update tbl_nrgnr_locations set habitat = 'Aquatic and Terrestrial' where habitat = 'Aquatic and terrestrial' --finds each individual observation and creates a view create view v_nrgnr_loc_w_obs As --selects utm x coord, utm y coord, common name, number spotted, year, event id, location id, location description, and habitat for vertebrate monitoring sites select l.utmx, l.utmy, s.commonname, d.number, e.year, d.recid, d.eventid,

l.locationid, l.locationDescript, l.habitatDescription, l.habitat --from the nrgnr locations, events, data, and species tables from tbl_nrgnr_locations As l, tbl_nrgnr_events As e, tbl_nrgnr_data As d, tbl_nrgnr_species As s where --events event id equals data event id e.eventid = d.eventid and --and species species id equals data species id s.speciesid = d.speciesid and --and location location id equals data location id l.locationid = d.locationid

You might also like