Sie sind auf Seite 1von 5

Dunlin Lab 06 write up

6.02
1. In order to update tblCity with the appropriate information we ran the following scripts
INSERT INTO tblCity (Name, Country, Population, Description, Mayor, Website)
VALUES ('Bradford on Avon', 'England', 9326, 'Bradford on Avon (BOA) is a town in west
Wiltshire,
England with a population of about 9,326. It is the smallest of the five town''s in West
Wiltshire.
The towns canal, historic buildings, shops, pubs and restaurants make it popular with
tourists.', 'Peter Leach',
'http://www.bradfordonavontown.com/')
6.03
2. In order to update the tblCommittee with the new information we ran the following scripts
INSERT INTO tblCommittee (CommitteeType, CommitteeName, MonthlyMeetingTime,
BudgetedExpenditures, ExpendituresToDate)
VALUES ('C', 'Bradford on Avon', '2nd Friday 2 PM', 500, 50)
INSERT INTO tblSisterCityCommittee (CommitteeID, CityID)
VALUES (29, 7)
UPDATE tblSisterCityCommittee
SET TopProject = 'Explore the possibility of a relationship between BOA and your SCA'
WHERE CommitteeID = 29
UPDATE tblSisterCityCommittee
SET MostRecentVisitToCity = '2004-08-12'
WHERE CommitteeID = 29
UPDATE tblSisterCityCommittee
SET AffiliatedCity = 'Bradford on Avon'
WHERE CommitteeID = 29
6.04
INSERT INTO tblCommittee (CommitteeType, CommitteeName, MonthlyMeetingTime,
BudgetedExpenditures, ExpendituresToDate)
VALUES ('S', 'Programs', '3rd Friday 7 PM', 500, 50)
6.05
INSERT INTO tblCommittee (CommitteeType, CommitteeName, MonthlyMeetingTime,
BudgetedExpenditures, ExpendituresToDate)

VALUES ('S', 'Baseball Series', '3rd Friday 12 pm', 500,150)


INSERT INTO tblSupportCommittee (CommitteeID, GovernmentContact, MissionStatement)
VALUES (31, 'Parks and Rec. Dir.', 'Establish a Pac Rim Series Baseball competition')
[req 6.10]
1. Download the DSCAOfficers excel table and then open the table. You will need to alter the
table to normalize it so it can be accurately imported into SQL.
Add a column for CommitteeName and fill the top title for the sections in this new column
created according to the correct correlation.
Take all the spaces out of the column titles.
Delete all rows that have heading titles or dont contain data.
Add a column named CommitteeType and fill the column accordingly S = SupportCommittee
and C = SisterCityCommittee
Add a column of CommitteeID and fill in the column accordingly so the committee type is
accurately matched with the correlating CommitteeID number from the tblCommittee table.
Remove the strikethrough from out all names of past employees.
2. Create the 3 final production tables tblPosition, tblAuthCommPosit, and tblServiceHistory
make sure to identify the appropriate primary keys and foreign keys. The script we used to
create the 3 tables is below.
/*Create tbl Position */
CREATE table tblPosition(
PositionID int not null primary key,
PositionName varchar(100),
);
/*Create tbl AuthCommPosit*/
CREATE table tblAuthCommPosit(
AuthCommPosit int not null primary key,
CommitteeID int not null,
PositionID int not null,
constraint FKCommitteeID foreign key (CommitteeID)
references tblCommittee(CommitteeID)
ON UPDATE CASCADE
ON DELETE NO ACTION,
constraint FKPositionID foreign key (PositionID)
references tblPosition(PositionID)
ON UPDATE CASCADE
ON DELETE NO ACTION
);
/*Create tblServiceHistory */

CREATE table tblServiceHistory(


StartDate date primary key,
PersonID int not null,
CommitteeID int not null,
PositionID int not null,
EndDate date,
constraint FKPersonID foreign key (PersonID)
references tblPerson(PersonID)
ON UPDATE CASCADE
ON DELETE NO ACTION,
);
/*designate the primary, foreign and unique keys according to the lab06 SQL workbench
design*/
3. Import the excel sheet and name it zOfficers table
4. Insert data into the 3 production tables from the staging table zOfficers
/*Insert the data into the tblPerson*/
INSERT INTO tblPerson (FirstName, MidName, LastName)
SELECT FirstName, MidName, LastName
FROM zOfficers
/*Alter the tblServiceHistory to accurately fill the data*/
ALTER TABLE tblServiceHistory
ADD FirstName varchar(25), MidName varchar(25), LastName varchar(30)
INSERT INTO tblServiceHistory (CommitteeID, StartDate, EndDate, FirstName, MidName,
LastName)
SELECT CommitteeID, StartDate, EndDate, FirstName, MidName, LastName
FROM zOfficers
WHERE StartDate is not NULL
UPDATE tblServiceHistory
SET PersonID = tblPerson.PersonID
FROM tblPerson
WHERE tblServiceHistory.FirstName = tblPerson.FirstName
AND tblServiceHistory.LastName = tblPerson.LastName
ALTER TABLE tblServiceHistory
DROP COLUMN FirstName, MidName, LastName
INSERT INTO tblPosition
(PositionName)

SELECT DISTINCT
PositionName
FROM zOfficers;
ALTER TABLE zOfficers
ADD PositionID int
UPDATE zOfficers
SET PositionID = 8 WHERE PositionName = 'Treasurer'
ALTER TABLE zOfficers
ADD PersonID int
UPDATE zOfficers
SET PersonID = tblPerson.PersonID
FROM tblPerson
WHERE zOfficers.FirstName = tblPerson.FirstName
AND zOfficers.LastName = tblPerson.LastName
UPDATE tblServiceHistory
SET PositionID = zOfficers.PositionID
FROM zOfficers
WHERE tblServiceHistory.PersonID = zOfficers.PersonID
INSERT INTO tblAuthCommPosit (CommitteeID, PositionID)
SELECT CommitteeID, PositionID
FROM zOfficers
WHERE zOfficers.AuthCommPositID is not NULL
ALTER TABLE zOfficers
ADD AuthCommPositID int
UPDATE zOfficers
SET AuthCommPositID = 8 WHERE PositionName = 'Treasurer'
UPDATE tblAuthCommPosit
SET AuthCommPositID = zOfficers.AuthCommPositID
FROM zOfficers
WHERE tblAuthCommPosit.CommitteeID = zOfficers.CommitteeID
AND tblAuthCommPosit.PositionID = zOfficers.PositionID
INSERT INTO tblPerson (FirstName, MidName, LastName)
SELECT DISTINCT FirstName, MidName, LastName
FROM zOfficers

WHERE FirstName is not NULL


OR MidName is not NULL
OR LastName is not NULL

DELETE FROM tblServiceHistory


INSERT INTO tblServiceHistory (PersonID)
SELECT PersonID
FROM tblPerson AS P
WHERE FirstName = P.FirstName AND MidName = P.MidName AND LastName = P.LastName
INSERT INTO tblPosition
(PositionName)
SELECT DISTINCT
PositionName
FROM zOfficers;

Das könnte Ihnen auch gefallen