Question

In: Computer Science

I am coding in MySQL and two of my tables are populating find but the other...

I am coding in MySQL and two of my tables are populating find but the other two "Employee" and "Assignment" won't. I keep getting an error code saying I can't alter a child table and I can't figure out what to fix. Here is my code:

CREATE TABLE DEPARTMENT (

DepartmentName Char(35) NOT NULL,

BudgetCode Char(30) NOT NULL,

OfficeNumber Char(15) Not Null,

DepartmentPhone Char(12) NOT NULL,

CONSTRAINT DEPARTMENT_PK primary key(DepartmentName)

);

CREATE TABLE EMPLOYEE(

EmployeeNumber Int NOT NULL AUTO_INCREMENT,

FirstName Char(25) NOT NULL,

LastName Char(25) NOT NULL,

Department Char(35) NOT NULL DEFAULT 'Human Resources',

Position Char(35) NULL,

Supervisor Int NULL,

OfficePhone Char(12) NULL,

EmailAddress VarChar(100) NOT NULL UNIQUE,

CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber),

CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department)

REFERENCES DEPARTMENT(DepartmentName)

ON UPDATE CASCADE,

CONSTRAINT EMP_SUPER_FK FOREIGN KEY(Supervisor)

REFERENCES EMPLOYEE(EmployeeNumber)

);

ALTER TABLE EMPLOYEE AUTO_INCREMENT=1;



CREATE TABLE PROJECT(

ProjectID Int NOT NULL AUTO_INCREMENT,

ProjectName Char(50) NOT NULL,

Department Char(35) NOT NULL,

MaxHours Numeric(8,2) NOT NULL DEFAULT 100,

StartDate Date NULL,

EndDate Date NULL,

CONSTRAINT PROJECT_PK PRIMARY KEY(ProjectID),

CONSTRAINT PROJ_DEPART_FK FOREIGN KEY(Department)

REFERENCES DEPARTMENT(DepartmentName)

ON UPDATE CASCADE

);

ALTER TABLE PROJECT AUTO_INCREMENT=1000;

CREATE TABLE ASSIGNMENT (

ProjectID Int NOT NULL,

EmployeeNumber Int NOT NULL,

HoursWorked Numeric(6,2) NULL,

CONSTRAINT ASSIGNMENT_PK PRIMARY KEY(ProjectID, EmployeeNumber),

CONSTRAINT ASSIGN_PROJ_FK FOREIGN KEY(ProjectID)

REFERENCES PROJECT(ProjectID)

ON UPDATE NO ACTION

ON DELETE CASCADE,

CONSTRAINT ASSIGN_EMP_FK FOREIGN KEY(EmployeeNumber)

REFERENCES EMPLOYEE(EmployeeNumber)

ON UPDATE NO ACTION

ON DELETE NO ACTION

);

INSERT Department(DepartmentName, BudgetCode, OfficeNumber, DepartmentPhone)

VALUES('Administration', 'BC-100-10', 'BLDG01-201', '360-285-8100'),

('LEGAL', 'BC-200-10', 'BLDG01-220', '360-285-8200'),

('Human Resources', 'BC-300-10', 'BLDG01-230', '360-285-8300'),

('Finance', 'BC-400-10', 'BLDG01-110', '360-285-8400'),

('Accounting', 'BC-500-10', 'BLDG01-120', '360-285-8405'),

('Sales and Marketing','BC-600-10', 'BLDG01-250', '360-285-8500'),

('InfoSysems', 'BC-700-10', 'BLDG02-210', '360-285-8600'),

('Research and Development', 'BC-800-10', 'BLDG02-250', '360-285-8700'),

('Production', 'BC-900-10', 'BLDG02-110', '360-285-8800')

INSERT Employee(EmployeeNumber, FirstName, LastName, Department, Position, Supervisor, OfficePhone, EmailAddress)

VALUES('1', 'Mary', 'Jacobs', 'Administration', 'CEO', NULL, '360-285-8110', '[email protected]'),

('2', 'Rosalie', 'Jackson', 'Administration', 'AdminAsst', '1', '360-825-8120', '[email protected]'),

('3', 'Richard', 'Bandalone', 'Legal', 'Attorney', '1', '360-285-8210', '[email protected]'),

('4', 'George', 'Smith', 'Human Resources', 'HR3', '1', '360-285-8310', '[email protected]'),

('5','Alan', 'Adams', 'Human Resources', 'HR1', '4', '360-285-8320', '[email protected]'),

('6', 'Ken', 'Evans', 'Finance', 'CFO', '1', '360-285-8410', '[email protected]'),

('7', 'Mary', 'Abernathy', 'Finance', 'FA3', '6', '360-285-8420', '[email protected]'),

('8', 'Tom', 'Caruthers', 'Accounting', 'FA2', '6', '360-285-8430', '[email protected]'),

('9', 'Heather', 'Jones', 'Accounting', 'FA2', '6', '360-825-8440', '[email protected]'),

('10', 'Ken', 'Numoto', 'Sales and Marketing', 'SM3', '1', '360-285-8510', '[email protected]'),

('11', 'Linda', 'Granger', 'Sales and Marketing', 'SM3', '10', '360-285-8520', '[email protected]'),

('12', 'James', 'Nestor', 'InfoSystems', 'CIO', '1', '360-285-8610', '[email protected]'),

('13', 'Rick', 'Brown', 'InfoSystems', 'IS2', '12', NULL, '[email protected]'),

('14', 'Mike', 'Nguyen', 'Research and Development', 'CTO', '1', '360-285-8710', '[email protected]'),

('15', 'Jason', 'Sleeman', 'Research and Development', 'RD3', '14', '360-285-8720', '[email protected]'),

('16', 'Mary', 'Smith', 'Production', 'OPS3', '1', '360-825-8810', '[email protected]'),

('17', 'Tom', 'Jackson', 'Production', 'OPS2', '16', '360-825-8820', '[email protected]'),

('18', 'George', 'Jones', 'Production', 'CPS2', '17', '360-825-8830', '[email protected]'),

('19', 'Julia', 'Hayakawa', 'Production', 'CPS1', '17', NULL, '[email protected]'),

('20', 'Sam', 'Stewart', 'Production', 'OPS1', '17', NULL, '[email protected]')

INSERT Project(ProjectID, ProjectName, Department, MAxHours, StartDate, EndDate)

VALUES ('1000', '2017 Q3 Production Plan', 'Production', '100.00', '05/10/17', '2017-06-15'),

('1100', '2017 Q3 Marketing Plan', 'Sales and Marketing', '135.00', '05/10/17', '2017-06-15'),

('1200', '2017 Q3 Portfolio Analysis', 'Finance', '120.00', '07/05/17', '2017-07-25'),

('1300', '2017 Q3 Tax Preparation', 'Accounting', '145.00', '08/10/17', '2017-10-15'),

('1400', '2017 Q4 Production Plan', 'Production', '100.00', '08/10/17', '2017-09-15'),

('1500', '2017 Q4 Marketing Plan', 'Sales and Marketing', '135.00', '08/10/17', '2017-09-15'),

('1600', '2017 Q4 Portfolio Analysis', 'Finance', '140.00', '10/05/17', NULL)








INSERT Assignment(ProjectID, EmployeeNumber, HoursWorked)

VALUES('1000', '1', '30.00'),

('1000', '6', '50.00'),

('1000', '10', '50.00'),

('1000', '16', '75.00'),

('1000', '17', '75.00'),

('1100', '1', '30.00'),

('1100', '6', '75.00'),

('1100', '10', '55.00'),

('1100', '11', '55.00'),

('1200', '3', '20.00'),

('1200', '6', '40.00'),

('1200', '7', '45.00'),

('1200', '8', '45.00'),

('1300', '3', '25.00'),

('1300', '6', '40.00'),

('1300', '8', '50.00'),

('1300', '9', '50.00'),

('1400', '1', '30.00'),

('1400', '6', '50.00'),

('1400', '10', '50.00')



Solutions

Expert Solution

Short Summary:

  • Error has been found and fixed.

**************Please upvote the answer and appreciate our time.************

Solution:

Erro:

Foreign key violation occurs in Insertion statement 12 and 13 because of department key violation.

In Department table, spelling mistake

('InfoSysems', 'BC-700-10', 'BLDG02-210', '360-285-8600');

In Employee table ,

('12', 'James', 'Nestor', 'InfoSystems', 'CIO', '1', '360-285-8610', '[email protected]'),
('13', 'Rick', 'Brown', 'InfoSystems', 'IS2', '12', NULL, '[email protected]')

Fix:

Either change the key name in department table as "InfoSystems" and run the employee table code you have.

Correct Solution:

  • Just changed one line in Department table

CREATE TABLE DEPARTMENT (
DepartmentName Char(35) NOT NULL,
BudgetCode Char(30) NOT NULL,
OfficeNumber Char(15) Not Null,
DepartmentPhone Char(12) NOT NULL,
CONSTRAINT DEPARTMENT_PK primary key(DepartmentName)
);

CREATE TABLE EMPLOYEE(
EmployeeNumber Int NOT NULL AUTO_INCREMENT,
FirstName Char(25) NOT NULL,
LastName Char(25) NOT NULL,
Department Char(35) NOT NULL DEFAULT 'Human Resources',
Position Char(35) NULL,
Supervisor Int NULL,
OfficePhone Char(12) NULL,
EmailAddress VarChar(100) NOT NULL UNIQUE,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber),
CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE,
CONSTRAINT EMP_SUPER_FK FOREIGN KEY(Supervisor)
REFERENCES EMPLOYEE(EmployeeNumber)
);

ALTER TABLE EMPLOYEE AUTO_INCREMENT=1;

CREATE TABLE PROJECT(
ProjectID Int NOT NULL AUTO_INCREMENT,
ProjectName Char(50) NOT NULL,
Department Char(35) NOT NULL,
MaxHours Numeric(8,2) NOT NULL DEFAULT 100,
StartDate Date NULL,
EndDate Date NULL,
CONSTRAINT PROJECT_PK PRIMARY KEY(ProjectID),
CONSTRAINT PROJ_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE
);

ALTER TABLE PROJECT AUTO_INCREMENT=1000;

CREATE TABLE ASSIGNMENT (
ProjectID Int NOT NULL,
EmployeeNumber Int NOT NULL,
HoursWorked Numeric(6,2) NULL,
CONSTRAINT ASSIGNMENT_PK PRIMARY KEY(ProjectID, EmployeeNumber),
CONSTRAINT ASSIGN_PROJ_FK FOREIGN KEY(ProjectID)
REFERENCES PROJECT(ProjectID)
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT ASSIGN_EMP_FK FOREIGN KEY(EmployeeNumber)
REFERENCES EMPLOYEE(EmployeeNumber)
ON UPDATE NO ACTION
ON DELETE NO ACTION
);


INSERT Department(DepartmentName, BudgetCode, OfficeNumber, DepartmentPhone)
VALUES('Administration', 'BC-100-10', 'BLDG01-201', '360-285-8100'),
('LEGAL', 'BC-200-10', 'BLDG01-220', '360-285-8200'),
('Human Resources', 'BC-300-10', 'BLDG01-230', '360-285-8300'),
('Finance', 'BC-400-10', 'BLDG01-110', '360-285-8400'),
('Accounting', 'BC-500-10', 'BLDG01-120', '360-285-8405'),
('Sales and Marketing','BC-600-10', 'BLDG01-250', '360-285-8500'),
('InfoSystems', 'BC-700-10', 'BLDG02-210', '360-285-8600'),
('Research and Development', 'BC-800-10', 'BLDG02-250', '360-285-8700'),
('Production', 'BC-900-10', 'BLDG02-110', '360-285-8800');

INSERT Employee(EmployeeNumber, FirstName, LastName, Department, Position, Supervisor, OfficePhone, EmailAddress)
VALUES('1', 'Mary', 'Jacobs', 'Administration', 'CEO', NULL, '360-285-8110', '[email protected]'),
('2', 'Rosalie', 'Jackson', 'Administration', 'AdminAsst', '1', '360-825-8120', '[email protected]'),
('3', 'Richard', 'Bandalone', 'Legal', 'Attorney', '1', '360-285-8210', '[email protected]'),
('4', 'George', 'Smith', 'Human Resources', 'HR3', '1', '360-285-8310', '[email protected]'),
('5','Alan', 'Adams', 'Human Resources', 'HR1', '4', '360-285-8320', '[email protected]'),
('6', 'Ken', 'Evans', 'Finance', 'CFO', '1', '360-285-8410', '[email protected]'),
('7', 'Mary', 'Abernathy', 'Finance', 'FA3', '6', '360-285-8420', '[email protected]'),
('8', 'Tom', 'Caruthers', 'Accounting', 'FA2', '6', '360-285-8430', '[email protected]'),
('9', 'Heather', 'Jones', 'Accounting', 'FA2', '6', '360-825-8440', '[email protected]'),
('10', 'Ken', 'Numoto', 'Sales and Marketing', 'SM3', '1', '360-285-8510', '[email protected]'),
('11', 'Linda', 'Granger', 'Sales and Marketing', 'SM3', '10', '360-285-8520', '[email protected]'),
('12', 'James', 'Nestor', 'InfoSystems', 'CIO', '1', '360-285-8610', '[email protected]'),
('13', 'Rick', 'Brown', 'InfoSystems', 'IS2', '12', NULL, '[email protected]'),
('14', 'Mike', 'Nguyen', 'Research and Development', 'CTO', '1', '360-285-8710', '[email protected]'),
('15', 'Jason', 'Sleeman', 'Research and Development', 'RD3', '14', '360-285-8720', '[email protected]'),
('16', 'Mary', 'Smith', 'Production', 'OPS3', '1', '360-825-8810', '[email protected]'),
('17', 'Tom', 'Jackson', 'Production', 'OPS2', '16', '360-825-8820', '[email protected]'),
('18', 'George', 'Jones', 'Production', 'CPS2', '17', '360-825-8830', '[email protected]'),
('19', 'Julia', 'Hayakawa', 'Production', 'CPS1', '17', NULL, '[email protected]'),
('20', 'Sam', 'Stewart', 'Production', 'OPS1', '17', NULL, '[email protected]')


INSERT Project(ProjectID, ProjectName, Department, MAxHours, StartDate, EndDate)
VALUES ('1000', '2017 Q3 Production Plan', 'Production', '100.00', '05/10/17', '2017-06-15'),
('1100', '2017 Q3 Marketing Plan', 'Sales and Marketing', '135.00', '05/10/17', '2017-06-15'),
('1200', '2017 Q3 Portfolio Analysis', 'Finance', '120.00', '07/05/17', '2017-07-25'),
('1300', '2017 Q3 Tax Preparation', 'Accounting', '145.00', '08/10/17', '2017-10-15'),
('1400', '2017 Q4 Production Plan', 'Production', '100.00', '08/10/17', '2017-09-15'),
('1500', '2017 Q4 Marketing Plan', 'Sales and Marketing', '135.00', '08/10/17', '2017-09-15'),
('1600', '2017 Q4 Portfolio Analysis', 'Finance', '140.00', '10/05/17', NULL);

INSERT Assignment(ProjectID, EmployeeNumber, HoursWorked)
VALUES('1000', '1', '30.00'),
('1000', '6', '50.00'),
('1000', '10', '50.00'),
('1000', '16', '75.00'),
('1000', '17', '75.00'),
('1100', '1', '30.00'),
('1100', '6', '75.00'),
('1100', '10', '55.00'),
('1100', '11', '55.00'),
('1200', '3', '20.00'),
('1200', '6', '40.00'),
('1200', '7', '45.00'),
('1200', '8', '45.00'),
('1300', '3', '25.00'),
('1300', '6', '40.00'),
('1300', '8', '50.00'),
('1300', '9', '50.00'),
('1400', '1', '30.00'),
('1400', '6', '50.00'),
('1400', '10', '50.00')

**************************************************************************************

Feel free to rate the answer and comment your questions, if you have any.

Please upvote the answer and appreciate our time.

Happy Studying!!!

**************************************************************************************


Related Solutions

If I am looking to maximize my investment as an investor and the company I am...
If I am looking to maximize my investment as an investor and the company I am looking at has a low or unstable payout schedule, what would be the point of investing?
I am not able to upload a image of the question or in tables as it...
I am not able to upload a image of the question or in tables as it is formated. Any suggestions how i can do this? Thank you Penny’s Rent A Car Penny’s Rent a Car offers three rental plans as shown in Table 1. Please note that the fixed cost is provided in terms of months. Later, you will be asked to construct a cost table in terms of annual cost. Table 1. Rental plan characteristics Plan Fixed Monthly Payment...
"How can I connect my hadoop database or mysql database server to my d3 visual?"
"How can I connect my hadoop database or mysql database server to my d3 visual?"
Screenshots from MySQL (or any other software you use) of all the tables after queries result...
Screenshots from MySQL (or any other software you use) of all the tables after queries result sorry no spam i will be reported no copy and paste i want complete answer with Screenshots no handwriting thanks for your efforts and time Using the info below, write a query SQL Using the info below to Normalize the Tables (in 3NF at least) . Using the info below toCreate the Normalized Tables and Populate them with at least 5 Rows . Using...
1. I am trying to determine the level of measurement of my data type? I am...
1. I am trying to determine the level of measurement of my data type? I am looking for advice on Nominal, Ordinal, Interval, and Ratio 2. Does the data set have any categorical variables? I am trying to Describe the data set below in very general terms? This data consist of 8 variables: Which are GRE Scores, TOEFL Scores, University Rating, Statement of Purpose, Letter of Recommendation Strength, Undergraduate GPA, . Research Experience, and Chance of Admit. Name Type Description...
I am trying to start saving for retirement. I am investing all my cash into the...
I am trying to start saving for retirement. I am investing all my cash into the S&P 500, which will assume consistently 9.8% interest, compounded annually. I initially put a lump sum of $100 into my account, and I will deposit $10 every second week. a) After 10 years, how much money will I have invested? b) After 10 years, if I sold all of my stocks, how much money will I have in my account? c) After 25 years,...
I am doing a paper on stressors and my stressor is my job. I have had...
I am doing a paper on stressors and my stressor is my job. I have had an arguement with a superior who is know for being a bully, but i stood up to him and could end up unemployed. Having four kids, a wife, and bills to pay, this could be devastating. Using this stressor, what physiological changes occur in the brain due to the stress response? And what emotional and cognitive effects might occur due to this stressful situation?
I am writing a program that will work with two other files to add or subtract...
I am writing a program that will work with two other files to add or subtract fractions for as many fractions that user inputs. I need to overload the + and - and << and >> opperators for the assignment. The two files posted cannot be modified. Can someone correct the Fraction.ccp and Frction.h file that I am working on? I'm really close. // // useFraction.cpp // // DO NOT MODIFY THIS FILE // #include "Fraction.h" #include<iostream> using namespace std;...
I worked on this my self but I am not sure about it and I feel...
I worked on this my self but I am not sure about it and I feel like I get confuse in explaining some of them, I want to capare and contrast the different types of membrane transport processes.( including differences and similarities) simple diffusion facilitated difusion osmosis primaryactive transport secendary active transport vesicular transport The comparison and similarities should be about each of these topics. 1.direction of transport 2.energy requirement 3.protein requirement 4.types of protein if applicable 5. example of...
Best Forecasting Model Hi, I am trying to find the best suitable model for my project...
Best Forecasting Model Hi, I am trying to find the best suitable model for my project that I should use for forecasting the values. Following are the models that I used and their respected values. Model RMSE MAE MAPE Holt's 201.616 130.072 2.054 Holt's (Log Transform) 197.723 125.330 1.971 Damped Trent .    206.040 128.525 2.028
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT