Assignment: SQL #2 Putting Information into a Database

Slides:



Advertisements
Similar presentations
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Advertisements

10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
Introduction to Information and Computer Science
SQLite 1 CS440. What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Form and Graphical User Interfaces. Lesson plan More about queries More about entering data into a table Form.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
DEFAULT Values and the MERGE Statement. 2 home back first prev next last What Will I Learn? Understand when to specify a DEFAULT value. Construct and.
SELECT e.NationalIDNumber, p.FirstName,p.LastName, City FROM HumanResources.Employee e INNER JOIN Person.Person p on p.BusinessEntityID = e.BusinessEntityID.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
Exam 2 Review. SQL – Create Table REMEMBER!! – Create table mxws.Contact ( ContactID INT(10) NOT NULL,.., primary key (contactID));
Exam 2 Review: SQL In, Dimensional Modeling, Pivot Tables, ETL Describe data cube elements Understand facts, dimensions, granularity Create/read a Star.
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
How to: SQL By: Sam Loch.
Prepared By: Bobby Wan Microsoft Access Prepared By: Bobby Wan
CS SQL.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Insert, Update and the rest…
Introduction to SQL 2016 Temporal Tables
MIS2502: Data Analytics SQL – Putting Information Into a Database
Instructor: Jason Carter
Manipulating Data.
All Powder Board and Ski
MIS2502: Data Analytics SQL – Putting Information Into a Database
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Enter your , phone, etc Enter your , phone, etc
Insert, Update, Delete Manipulating Data.
MIS2502: Data Analytics SQL – Putting Information Into a Database
SQL data definition using Oracle
Yong Choi School of Business CSU, Bakersfield
“Manipulating Data” Lecture 6.
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Yong Choi School of Business CSU, Bakersfield
Enter your name, , phone number etc.
Place all the time and date information for all your events
SQL DATA CONSTRAINTS.
MIS2502: Data Analytics SQL – Putting Information Into a Database
“Manipulating Data” Lecture 6.
MIS2502: Data Analytics SQL – Putting Information Into a Database
Rob Gleasure robgleasure.com
Chapter 2 Views.
Using CASE Value expression
MIS2502: Data Analytics SQL – Putting Information Into a Database
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
Non-selection queries
IST 318 Database Administration
Instructor Information: Mark Jamil
Instructor: SAMIA ARSHAD
Including Constraints
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
SQL NOT NULL Constraint
SQL AUTO INCREMENT Field
Presentation transcript:

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

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!!!

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, Email VARCHAR(45) NULL, Phone VARCHAR(12) NULL, PRIMARY KEY (ContactID), FOREIGN KEY (CompanyID) REFERENCES m80ws.Company(CompanyID) );

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, Email VARCHAR(45) NULL, Phone VARCHAR(12) NULL, PRIMARY KEY (EmployeeID) );

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));

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');

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,Email,Phone) VALUES (501,110,'Jack','Lee','4777 Cameron Rd.','Buffalo','NY', '14209',1,'jlee@urbanout.com','215-454-5500'); INSERT INTO m80ws.Contact (ContactID,CompanyID,FirstName,LastName,Street,City,State,Zip,IsMain,Email,Phone) VALUES (502,111,'Bonnie','Johnson','3600 Elk City Rd.','Ridley Park','PA', '19078',1,'bj@tollbrothers.com','215-938-8000');

6. Statements that add the following three Employees to the Employee table INSERT INTO m80ws.Employee (EmployeeID,FirstName,LastName,Salary, HireDate,JobTitle,Email,Phone) VALUES (1001,'Dianne','Connor',85000, '2011-08-12', 'Sales Manager','dconnor@marketco.com','215-555-5678’); INSERT INTO m80ws.Employee (EmployeeID,FirstName,LastName,Salary, HireDate,JobTitle,Email,Phone) VALUES (1002,'Lesley',’Bloom',70000, '2012-07-01', 'Sales Representative',’lbloom@marketco.com','215-555-5679');

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,'2018-02-05', Emailed new marketing plan for approval'); INSERT INTO m80ws.ContactEmployee (ContactEmployeeID,ContactID,EmployeeID,ContactDate,Description) VALUES (5002,501,1001,'2018-02-08','Phone call to discuss pricing for advertising');

8. In the Employee table, the statement that changes Lesley Bloom’s phone number to 215-555-8800 UPDATE m80ws.Employee SET Phone='215-555-8800' 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. 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