Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment: SQL #2 Putting Information into a Database

Similar presentations


Presentation on theme: "Assignment: SQL #2 Putting Information into a Database"— Presentation transcript:

1 Assignment: SQL #2 Putting Information into a Database
Solution Key

2 Details You May Miss in SQL
Basic Syntax offered in the Exam! CREATE TABLE: Do not forget the foreign key Use curly braces for foreign key REFERENCES foreign key REFERENCES: Primary table name is optional, foreign referred table name is required!!!

3 1. Statement to create the Contact table
CREATE TABLE m80ws.Contact ( ContactID INT NOT NULL, CompanyID INT NULL, FirstName VARCHAR(45) NULL, LastName VARCHAR(45) NULL, Street VARCHAR(45) NULL, City VARCHAR(45) NULL, State VARCHAR(2) NULL, Zip VARCHAR(10) NULL, IsMain BOOLEAN NULL, VARCHAR(45) NULL, Phone VARCHAR(12) NULL, PRIMARY KEY (ContactID), FOREIGN KEY (CompanyID) REFERENCES m80ws.Company(CompanyID) );

4 2. Statement to create the Employee table
CREATE TABLE m80ws.Employee ( EmployeeID INT NOT NULL, FirstName VARCHAR(45) NULL, LastName VARCHAR(45) NULL, Salary DECIMAL(10,2) NULL, HireDate DATE NULL, JobTitle VARCHAR(25) NULL, VARCHAR(45) NULL, Phone VARCHAR(12) NULL, PRIMARY KEY (EmployeeID) );

5 3. Statement to create the ContactEmployee table
CREATE TABLE m80ws.ContactEmployee ( ContactEmployeeID INT(10) NOT NULL, ContactID INT(10) NULL, EmployeeID INT(10) NULL, ContactDate DATE NULL, Description VARCHAR(100) NULL, PRIMARY KEY (ContactEmployeeID), FOREIGN KEY (ContactID) REFERENCES m80ws.Contact(ContactID), FOREIGN KEY (EmployeeID) REFERENCES m80ws.Employee(EmployeeID));

6 4. Statements that add the following two Companies to the Company table
INSERT INTO m80ws.Company (CompanyID, CompanyName, Street, City, State, Zip) VALUES (110,' Urban Outfitters, Inc.', 5000 South Broad St.',' Philadelphia ','PA','19112'); INSERT INTO m80ws.Company (CompanyID, CompanyName, Street, City, State, Zip) VALUES (111,' Toll Brothers','250 Gibraltar Rd.','Horsham','PA','19044');

7 5. Statements that add the following three Contacts to the Contact table
INSERT INTO m80ws.Contact (ContactID,CompanyID,FirstName,LastName,Street,City,State,Zip,IsMain, ,Phone) VALUES (501,110,'Jack','Lee','4777 Cameron Rd.','Buffalo','NY', INSERT INTO m80ws.Contact (ContactID,CompanyID,FirstName,LastName,Street,City,State,Zip,IsMain, ,Phone) VALUES (502,111,'Bonnie','Johnson','3600 Elk City Rd.','Ridley Park','PA',

8 6. Statements that add the following three Employees to the Employee table
INSERT INTO m80ws.Employee (EmployeeID,FirstName,LastName,Salary, HireDate,JobTitle, ,Phone) VALUES (1001,'Dianne','Connor',85000, ' ', 'Sales INSERT INTO m80ws.Employee (EmployeeID,FirstName,LastName,Salary, HireDate,JobTitle, ,Phone) VALUES (1002,'Lesley',’Bloom',70000, ' ', 'Sales

9 7. Statements that record the following contact events in the ContactEmployee table
INSERT INTO m80ws.ContactEmployee (ContactEmployeeID,ContactID,EmployeeID,ContactDate,Description) VALUES (5001,502,1002,' ', ed new marketing plan for approval'); INSERT INTO m80ws.ContactEmployee (ContactEmployeeID,ContactID,EmployeeID,ContactDate,Description) VALUES (5002,501,1001,' ','Phone call to discuss pricing for advertising');

10 8. In the Employee table, the statement that changes Lesley Bloom’s phone number to 215-555-8800
UPDATE m80ws.Employee SET Phone=' ' WHERE EmployeeID = 1002; 9. In the Company table, the statement that changes the name of “Urban Outfitters, Inc.” to “Urban Outfitters” UPDATE m80ws.Company SET CompanyName=' Urban Outfitters' WHERE CompanyID = 110; 10. In ContactEmployee table, the statement that removes Dianne Connor’s contact event with Jack Lee DELETE FROM m80ws.ContactEmployee WHERE ContactEmployeeID=5002;

11 11. SQL SELECT query that displays the names of the employees that have contacted Wegmans Food Markets SELECT Employee.FirstName,Employee.LastName FROM m80ws.Employee,m80ws.ContactEmployee, m80ws.Contact,m80ws.Company WHERE Company.CompanyID=Contact.CompanyID AND Contact.ContactID=ContactEmployee.ContactID AND Employee.EmployeeID=ContactEmployee.EmployeeID AND Company.CompanyName=‘Toll Brothers'; Results: Lesley Bloom


Download ppt "Assignment: SQL #2 Putting Information into a Database"

Similar presentations


Ads by Google