Question

I am creating a database, using MYSQL and have inserted data however when I try and delete a row I have no luck can somebody please help me understand why the row doesn't delete? I have provided the created table the insert statements and the delete statement I used keep in mind the table displays as if it is full.

 CREATE TABLE IF NOT EXISTS `new_schema2`.`Employee` (
  `EID` INT NOT NULL,
  `Fname` VARCHAR(45) NOT NULL,
  `Lname` VARCHAR(45) NOT NULL,
  `AddressID` INT NOT NULL,
  `PayLevel` Decimal NOT NULL,
  `Jobtitle` VARCHAR(45) NOT NULL,
  `DateofEmployment` DATE NOT NULL,
  PRIMARY KEY (`EID`))
ENGINE = InnoDB;

#Inserts begin Here
INSERT INTO new_schema2.Employee 
       (EID, Fname, Lname, AddressID, PayLevel, Jobtitle, DateofEmployment) 
       VALUES 
   (    0,'Andrew','Wiggins','7', 10000.00,'Stock Boy','08/11/12' );

INSERT INTO new_schema2.Employee 
       (EID, Fname, Lname, AddressID, PayLevel, Jobtitle, DateofEmployment) 
       VALUES 
       (1,'Andrew','Wiggins','7', 10000.00,'Stock Boy','08/11/12' );

INSERT INTO new_schema2.Employee  
       (EID, Fname, Lname, AddressID, PayLevel, Jobtitle, DateofEmployment) 
       VALUES 
       ('2','Nick','Smith','8', 20000.00,'Cashier','08/10/09' );


 INSERT INTO new_schema2.Employee 
       (EID, Fname, Lname, AddressID, PayLevel, Jobtitle, DateofEmployment) 
       VALUES 
       ('3','Niko','Jackson','9',40000.00,'Manager','05/10/06' );

INSERT INTO new_schema2.Employee 
       (EID, Fname, Lname, AddressID, PayLevel, Jobtitle, DateofEmployment) 
       VALUES 
       ('4','Dante','Henderson','10', 20000.00,'Cashier','06/15/09' );

INSERT INTO new_schema2.Employee 
       (EID, Fname, Lname, AddressID, PayLevel, Jobtitle, DateofEmployment) 
       VALUES 
       ('5','Jessica','Smith','8',22000.00,'Performer','08/09/11' );

INSERT INTO new_schema2.Employee 
       (EID, Fname, Lname, AddressID, PayLevel, Jobtitle, DateofEmployment) 
       VALUES 
       ('6','Alex','Grossi','15',100000.00,'Owner','08/11/02' );

#Delete statements begin here
DELETE FROM new_schema2.employee
WHERE EID = 0 AND Fname='Andrew' AND Lname='Wiggins' AND AddressID='7' AND  DateofEmployment='11/12/08'  AND PayLevel='10000.00'AND  Jobtitle = 'Stock Boy'; 
Was it helpful?

Solution 2

The reason its not deleting because its failing on date condition.

You have field as

`DateofEmployment` DATE NOT NULL

When you insert 08/11/12 in MySQL it will become as 2008-11-12

So the delete command should be as

DELETE FROM Employee
WHERE EID = 0 
AND Fname='Andrew' 
AND Lname='Wiggins' 
AND AddressID='7' 
AND  DateofEmployment='2008-11-12'  
AND PayLevel='10000.00'
AND Jobtitle = 'Stock Boy';

Check with

SELECT DateofEmployment FROM Employee

And see how data is shown, you will get the answer by yourself.

OTHER TIPS

you dont need to specify all columns in your delete

Use just this

   DELETE FROM new_schema2.employee
   WHERE EID = 0 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top