Question

In: Computer Science

A new company is planning to build a new database system for holding information about customers...

A new company is planning to build a new database system for holding information about customers and salesmen. ‘Customers’, ‘Salesmen’ and ‘Customers_Salesmen’ are part of the information that the new company wants to store in the new database. These tables are shown below in figure 1, figure 2 and figure 3. The new company intends to use MySQL for building the new database.

Customer_ID

Customer_Name

Customer_City

Customer_Grade

3002

Ahmad Salman

New York

100

3007

Mazen Ali

New York

200

3005

Sami Khalil

California

200

3008

Ashraf Ahmad

London

300

3004

Manal Faris

Paris

300

3009

Tahani Mahdi

Berlin

100

3003

Fawzi Jama

Moscow

200

3001

Tareq Mohsen

London

100

Figure 1: Customers table

Salesman_ID

Salesman_Name

Salesman_City

Salesman_Commission

5001

Naser Hamad

New York

0.15

5002

Rami Farhan

Paris

0.13

5006

Salem Alawi

Paris

0.14

5003

Faten Morad

San Jose

0.12

5007

Turkey Fahad

Rome

0.13

5005

Juma Khalaf

London

0.11

Figure 2: Salesmen table

Customer_ID

Salesman_ID

3002

5001

3007

5001

3005

5002

3008

5002

3004

5006

3009

5003

3003

5007

3001

5005

Figure 3: Customers_Salesmen table

Based on the above three tables, answer the following 6 questions:

  1. Write an SQL statement for creating the customer table that is shown in figure 2. No need to write any SQL statement for adding any record to the customer table.  
  2. Write an SQL statement for adding one record to the customer table that was created in question-1 above. The added record should be one of the records that are given in the customer table.   
  3. Write an SQL statement to list the information of salesmen who work in Paris.
  4. Write an SQL statement to list all customer names who work with the salesman whose id is 5001.                                                                                                                           \
  5. Write an SQL statement to list all customer names who work with the salesman whose commission is 0.13.                                                                                                          ]
  6. Write an SQL statement to increase the salesman commission by 5%.

Solutions

Expert Solution

CREATE TABLE Customers(Customer_ID integer PRIMARY KEY, Customer_Name varchar(50), Customer_City varchar(50), Customer_Grade integer);

___________________________________________________________________

INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3002, 'Ahmad Salman', 'New York', 100);


___________________________________________________________________

SELECT * FROM Salesmen WHERE Salesman_City = 'Paris';


___________________________________________________________________



ALTER TABLE Customers_Salesmen ADD FOREIGN KEY (Customer_ID) REFERENCES Customers(Customer_ID);

ALTER TABLE Customers_Salesmen ADD FOREIGN KEY (Salesman_ID) REFERENCES Salesmen(Salesman_ID);

SELECT Customers.Customer_Name FROM Customers, Customers_Salesmen WHERE Customers.Customer_ID = Customers_Salesmen.Customer_ID AND Customers_Salesmen.Salesman_ID = 5001;


Ahmad Salman
Mazen Ali

___________________________________________________________________


SELECT Customers.Customer_Name FROM Customers, Customers_Salesmen, Salesmen  WHERE Customers.Customer_ID = Customers_Salesmen.Customer_ID AND Salesmen.Salesman_ID = Customers_Salesmen.Salesman_ID AND Salesmen.Salesman_Commission = 0.13;


Sami Khalil
Ashraf Ahmad
Fawzi Jama

___________________________________________________________________

UPDATE Salesmen SET Salesman_Commission = Salesman_Commission * 1.05;

___________________________________________________________________

CREATE TABLE Customers(Customer_ID integer PRIMARY KEY, Customer_Name varchar(50), Customer_City varchar(50), Customer_Grade real);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3002, 'Ahmad Salman', 'New York', 100);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3007, 'Mazen Ali', 'New York', 200);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3005, 'Sami Khalil', 'California', 200);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3008, 'Ashraf Ahmad', 'London', 300);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3004, 'Manal Faris', 'Paris', 300);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3009, 'Tahani Mahdi', 'Berlin', 100);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3003, 'Fawzi Jama', 'Moscow', 200);
INSERT INTO Customers(Customer_ID, Customer_Name, Customer_City, Customer_Grade) VALUES (3001, 'Tareq Mohsen', 'London', 100);
SELECT * FROM Customers;



CREATE TABLE Salesmen(Salesman_ID integer PRIMARY KEY, Salesman_Name varchar(50), Salesman_City varchar(50), Salesman_Commission real);
INSERT INTO Salesmen(Salesman_ID, Salesman_Name, Salesman_City, Salesman_Commission) VALUES (5001, 'Naser Hamad', 'New York', 0.15);
INSERT INTO Salesmen(Salesman_ID, Salesman_Name, Salesman_City, Salesman_Commission) VALUES (5002, 'Rami Farhan', 'Paris',0.13);
INSERT INTO Salesmen(Salesman_ID, Salesman_Name, Salesman_City, Salesman_Commission) VALUES (5006,'Salem Alawi','Paris',0.14);
INSERT INTO Salesmen(Salesman_ID, Salesman_Name, Salesman_City, Salesman_Commission) VALUES (5003,'Faten Morad','San,Jose',0.12);
INSERT INTO Salesmen(Salesman_ID, Salesman_Name, Salesman_City, Salesman_Commission) VALUES (5007,'Turkey Fahad','Rome',0.13);
INSERT INTO Salesmen(Salesman_ID, Salesman_Name, Salesman_City, Salesman_Commission) VALUES (5005,'Juma Khalaf','London',0.11);
SELECT * FROM Salesmen;


 
CREATE TABLE Customers_Salesmen(Customer_ID integer, Salesman_ID integer);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3002,5001);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3007,5001);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3005,5002);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3008,5002);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3004,5006);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3009,5003);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3003,5007);
INSERT INTO Customers_Salesmen(Customer_ID, Salesman_ID) VALUES (3001,5005);
SELECT * FROM Customers_Salesmen;

ALTER TABLE Customers_Salesmen ADD FOREIGN KEY (Customer_ID) REFERENCES Customers(Customer_ID);
ALTER TABLE Customers_Salesmen ADD FOREIGN KEY (Salesman_ID) REFERENCES Salesmen(Salesman_ID);

SELECT Customers.Customer_Name FROM Customers, Customers_Salesmen WHERE Customers.Customer_ID = Customers_Salesmen.Customer_ID AND Customers_Salesmen.Salesman_ID = 5001;

SELECT Customers.Customer_Name FROM Customers, Customers_Salesmen, Salesmen  WHERE Customers.Customer_ID = Customers_Salesmen.Customer_ID AND Salesmen.Salesman_ID = Customers_Salesmen.Salesman_ID AND Salesmen.Salesman_Commission = 0.13;

UPDATE Salesmen SET Salesman_Commission = Salesman_Commission * 1.05;
Select * from Salesmen;

___________________________________________________________________

Note: If you have queries or confusion regarding this question, please leave a comment. I would be happy to help you. If you find it to be useful, please upvote.


Related Solutions

A certain business keeps a database of information about its customers. A. Let C be the...
A certain business keeps a database of information about its customers. A. Let C be the rule which assigns to each customer shown in the table his or her home phone number. Is C a function? Explain your reasoning.
Your company maintains a database with information on your customers, and you are interested in analyzing...
Your company maintains a database with information on your customers, and you are interested in analyzing patters observed over the past quarter. 23% of customer in the database placed new orders within this period. However, for those customers who had a salesperson assigned to them, the new order rate was 58%. Overall, 14% of customers within the database had salesperson assigned to them. a) Draw a contingency table for this situation. b) What percentage of customers in the database placed...
Anyone can Give me an information about " Database System " which contains the definition, advantage,...
Anyone can Give me an information about " Database System " which contains the definition, advantage, component, disadvantage, applications, language, architected, levels, models, actors and operations.
How to generate database diagram for a database that stores information about the downloads that users...
How to generate database diagram for a database that stores information about the downloads that users make. Each user must have an email address, first name, and last name. Each user can have one or more downloads. Each download must have a filename and download date/time. Note: I want steps on how to generate this diagram using oracle SQL developer Each product can be related to one or more downloads. Each product must have a name.
The City of Pawnee, IN (not a real city) is planning to build a new hospital...
The City of Pawnee, IN (not a real city) is planning to build a new hospital next year that has a property value of $100 million. The Pawnee government plans to keep the property tax rate the same every year and to provide the same government services as they did last year. That is, the total budgeted expenditures and income from other sources will remain unchanged. Note: This question does not require any numerical calculations. Will the average amount of...
The municipality of a major city in Quebec is planning to build a new bridge to...
The municipality of a major city in Quebec is planning to build a new bridge to decrease the traffic load on the existing bridges connecting both sides of the city across the river. Construction is to start in 2020 and is expected to take four years at a cost of $25 million per year. After construction is completed, the cost of operation and maintenance is expected to be $2.5 million for the first year and to increase by 2.8% per...
You have decided to build the database for John’s system. This question centres around the development...
You have decided to build the database for John’s system. This question centres around the development of John’s database. Q.3.1 Draw any three tables you will include in John’s database. For each table, provide the following: a. Three fields. b. One record in each table. c. One primary key for each table. d. One foreign key. (20) Q.3.2 Design a logical view for the tables you have specified in Q.3.1. Note: You may use any software tool to create your...
our company is creating the database for the sales system. These are the major components: Database...
our company is creating the database for the sales system. These are the major components: Database design User entry form design Report design Access and authentication Maintenance You are assigned as an IT manager. For this Discussion, gather information from the library and research other web resources. Write a plan describing your role in designing, developing, managing, and supporting the database.
A company database needs to store information about employees (identified by ssn, with salary and phone...
A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments (identified by dno, with dname and budget as attributes), and children of employees (with name, age, and relationship to the employee as attributes). Employees work in departments; each department is managed by an employee; a child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. We...
4. Why would a company build an inter-enterprise information system and for that matter what is...
4. Why would a company build an inter-enterprise information system and for that matter what is such a system?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT