SQL Syntax Error/Cannot Add or update a child row - mysql

When I try to insert the values into the table "medlimir" I get this error:
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (2508962989_funi.medlimir, CONSTRAINT fk_medlimir_poststod1 FOREIGN KEY (poststod) REFERENCES poststod (postnumer) ON DELETE NO ACTION ON UPDATE NO ACTION)"
If I try to insert the values one by one, I get the following:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
I have no idea why this happens, I've looked at some similar questions but I haven't seen one that applies to this. Here's my code;
INSERT INTO medlimir VALUES
('ChildID1', 'Childname1', 'ChildHome1', 'Phone', 'Sport', 'M', '61907792409', 220),
('ChildID2', 'Childname2', 'Childhome2', 'Phone', 'Kúla', 'M', '15776113692', 220),
('ChildID3', 'Childname3', 'CHildHome3', 'Phone', 'Þríþraut', 'M', '94364592306', 111),
('ChildID4', 'Childname4', 'ChildHome4', 'Phone', 'Hlaup', 'M', '30848878228', 111),
('1410908008', 'Tsunayoshi Sawada', 'Namimori High', '6966873', 'Hlaup', 'M', '28028131468', 220),
('2608903265', 'Ryohei Sasagawa', 'Namimori Box', '4476920', 'Box', 'M', '91010668790', 220),
('0909906666', 'Gokudera Hayato', 'Namimori High', '1024632', 'Spjót', 'M', '63229758735', 220),
('2404903568', 'Takeshi Yamamoto', 'Namimori High', '', 'Kúla', 'M', '62750060985', 220),
('2501106575', 'Giotto Primo', 'Vongola Mansion', '', 'Langst.', 'M', '37282894310', 600),
('0512904873', 'Chrome Dokuro', 'Kokuyo', '', 'gólfleikf.', 'F', '17904297752', 111),
('0505903157', 'Hibari Kyoya', 'Kondo', '8018296', 'Tvíslá', 'M', '64388759435', 000),
('2805991337', 'Lambo', 'Namimori', '', 'Þríþraut', 'M', '81540318862', 600),
('1309035730', 'Reborn', 'Vongola Mansion', '6118960', 'Spjót', 'M', '45849294908', 600),
('0707031683', 'Colonnello', 'Vongola Mansion', '8663306', 'Kringla', 'M', '35282586046', 111),
('20020342489', 'Lal Mirch', 'Vongola Mansion', '947033', 'Kringla', 'F', '71126656838', 111);
The first 4 values were real, so I changed them a bit, rest is fake information. Any idea as to what may be wrong?

There is a missing symbol in the fifth line.
Instead of
('ChildID4', 'Childname4, 'ChildHome4', 'Phone', ...
it should be
('ChildID4', 'Childname4', 'ChildHome4', 'Phone', ...
^
|____ this is the missing symbol

Related

Conversion failed when converting date and / or time when creating a table

So I'am making a table with a char, varchar and date. I got an error message saying "Conversion failed when converting date and / or time". If anyone can help me fix, this you got sincere thank you. :D
this is my code for creating and inserting data on my table:
Create table Employee
(EMP_NUM char(3),
EMP_LNAME varchar(15),
EMP_FNAME varchar(15),
EMP_INITIAL char(1),
EMP_HIREDATE date,
JOB_CODE char (3),
EMP_YEARS char(2))
Insert into Employee (EMP_NUM, EMP_LNAME, EMP_FNAME, EMP_INITIAL,
EMP_HIREDATE, JOB_CODE)
Values (101, 'News', 'John', 'G','08-Nov-00', 502),
(102, 'Senior', 'David', 'H','12-Jul-89', 501),
(103, 'Arbough', 'June', 'E','01-Dec-96', 500),
(104, 'Ramoras', 'Anne', 'K','15-Nov-87', 501),
(105, 'Johnson', 'Alice', 'k','01-Feb-93', 502),
(106, 'Smithfield', 'William', null, '22-Jun-04', 500),
(107, 'Alonzo', 'Maria', 'D','10-Oct-93', 500),
(108, 'Washington', 'Ralph', 'B', '22-Aug-91',501),
(109, 'Smith', 'Larry', 'W', '18-Jul-97', 501),
(110, 'Olenko', 'Gerald', 'A', '11-Dec-95', 505),
(111, 'Wabash', 'Geoff', 'B', '04-Apr-91', 506),
(112, 'Smithson', 'Darlene', 'M', '23-Oct-94', 507),
(113, 'Joenbrood', 'Delbert', 'K', '15-ov-96', 508),
(114, 'Jones', 'Annelise', null, '20-Aug-93', 508),
(115, 'Bawangi', 'Travis', 'B','25-Jan-92', 501),
(116, 'Pratt', 'Gerald', 'L','05-Mar-97', 510),
(117, 'Williamson', 'Angie', 'M', '19-Jun-96', 509),
(118, 'Frommer', 'james', 'J','04-Jan-05', 510);
and this is the complete message result :
Msg 241, Level 16, State 1, Line 11
Conversion failed when converting date and/or time from character string.
Use CONVERSION for EMP_HIREDATE column for date :
For ex :
SELECT CAST('18-Jul-97' AS DATE)
In your query :
Insert into Employee (EMP_NUM, EMP_LNAME, EMP_FNAME, EMP_INITIAL,
EMP_HIREDATE, JOB_CODE)
SELECT 101, 'News', 'John', 'G',CAST('08-Nov-00' AS DATE), 502

restore a deleted data in my table to its original status

is there an sql code that will restore the data from my table, the table should contain the data that existed before I made the changes.
Here is my original data:
Insert into EMP_1 (EMP_NUM, EMP_LNAME,EMP_FNAME,EMP_INITIAL, EMP_HIREDATE, JOB_CODE)
values (103, 'Arbough', 'June', 'E', '01-Dec-96', 503),
(104, 'Ramoras', 'Anne', 'K','15-Nov-87', 501),
(105, 'Johnson', 'Alice', 'k','01-Feb-93', 502),
(106, 'Smithfield', 'William', null, '22-Jun-04', 500),
(107, 'Alonzo', 'Maria', 'D','10-Oct-93', 500),
(108, 'Washington', 'Ralph', 'B', '22-Aug-91', 501),
(109, 'Smith', 'Larry', 'W', '18-Jul-97', 501);
and heres the result after i deleted William Smithfield:
this is my code for deleting it:
Delete from EMP_1
where EMP_FNAME = 'William'
and EMP_LNAME = 'Smithfield'
and EMP_HIREDATE = '2004-06-22'
and JOB_CODE = 500
If you want to recover the data, no it is not possible with no history table.
Is there is a reason to do hard delete, I would suggest you to use soft delete, as in to have IsDeleted column in the table, and make it true or false, if you are not having and history tables.
if you want to reenter the data which you had, and you have first column as Identity column, then Set Identity off and on, and insert the data.

Is my SQL wrong or is it sqlfiddle?

I'm trying to better wrap my head around PIVOT in MySQL. I made a test table and query in SQLfiddle but I'm not getting it to work. I get the error:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'PIVOT ( COUNT p.[stat] FOR p.[title] IN (p.[title], p.[weight],
p.[length]' at line 3
Table and data:
CREATE TABLE pivoter (
amount int,
title varchar(20),
weight int,
length int,
stat varchar(10)
);
INSERT INTO pivoter VALUES (5, 'Blip', 13, 5, 'hold');
INSERT INTO pivoter VALUES (2, 'Crog', 10, 5, 'full');
INSERT INTO pivoter VALUES (2, 'Gump', 22, 1, 'hold');
INSERT INTO pivoter VALUES (10, 'Yark', 7, 12, 'fun');
INSERT INTO pivoter VALUES (0, 'Blim', 6, 1, 'full');
INSERT INTO pivoter VALUES (3, 'Fron', 5, 8, 'hold');
INSERT INTO pivoter VALUES (8, 'Xand', 2, 7, 'fun');
INSERT INTO pivoter VALUES (2, 'Xnor', 7, 9, 'hold');
INSERT INTO pivoter VALUES (4, 'Rugg', 7, 8, 'fun');
INSERT INTO pivoter VALUES (9, 'Lint', 4, 10, 'fun');
INSERT INTO pivoter VALUES (9, 'Pawn', 7, 2, 'hold');
INSERT INTO pivoter VALUES (0, 'Undr', 12, 11, 'hold');
INSERT INTO pivoter VALUES (14, 'Call', 1, 6, 'full');
Pivot Query:
select stat, title, weight, length, amount from pivoter p
PIVOT
(
COUNT p.[stat]
FOR p.[title]
IN (p.[title], p.[weight], p.[length], p.[amount])
) AS testedPivot;
In case you were wondering, no, the data isn't supposed to make sense. I just made garbage to try this out.
Is the problem with my query or sqlfiddle?
If it's my query what can I do to make this work?
If the problem is sqlfiddle, do you know of an alternative?
The query in the question looks like T-SQL syntax for Microsoft SQL Server.
This syntax is not valid in MySQL, for a couple of reasons.
PIVOT is not a valid keyword in MySQL.
And MySQL uses backticks to escape identifiers, not square brackets.

Getting undsired output on mysql data queries mysql

The following is my SQL data structure I'm trying out two queries as follows:
Select
Wrk_ID, Wrk_LastName, Skill_Desc
from
Worker, Skill
where
(UPPER(skill_desc) = UPPER('Map Designer') or
UPPER(skill_Desc) = UPPER('Game Designer'));
I'm getting twice the output that I need
select
wrk_ID, concat('Wrk_FirstName','Wrk_LastName') As FullName,
COUNT(Assign_ID) as Max_Assignment
from
assignment worker
group by
Wrk_ID, concat('Wrk_FirstName','Wrk_LastName');
In this query I'm getting the wrk_firstname and last name instead of the actual data of first and last name.
--
-- Dumping data for table `region`
--
INSERT INTO `region` (`Reg_ID`, `Reg_desc`) VALUES
('R0010', 'California'),
('R0011', 'Nevada'),
('R0012', 'Arizona'),
('R0013', 'Michigan'),
('R0014', 'New York'),
('R0015', 'Texas'),
('R0016', 'Washington'),
('R0017', 'Oregon'),
('R0018', 'Ohio'),
('R0019', 'Boston');
-- --------------------------------------------------------
--
-- Table structure for table `client`
--
INSERT INTO `client` (`Cli_ID`, `Cli_FirstName`, `Cli_LastName`, `Cli_Initial`, `Cli_StreetAddress`, `Cli_Sex`, `Cli_Phone`,`Reg_ID`) VALUES
('C0010', 'Krishneel', 'Sharma', 'V', '99 Rock Road', 'M', '844-2573', 'R0010'),
('C0011', 'Ravneel', 'Sharma', 'V', 'Cecil Street', 'M', '894-1238', 'R0011'),
('C0012', 'Brad', 'Pitt', 'W', '615 Devil Road', 'M', '894-2285', 'R0012'),
('C0013', 'Tom', 'Cruz', 'F', '615 Gorge Town', 'M', '894-2180', 'R0013'),
('C0014', 'Paul', 'Walker', 'F', '615 Gran Street', 'M', '222-1672', 'R0014'),
('C0015', 'Jeniffer','Lopez', 'B', '713 Tall Road', 'F', '442-3381','R0015'),
('C0016', 'Brown', 'James', 'G', '615 South Place', 'F', '297-1228', 'R0016'),
('C0017', 'Lady', 'Gaga', 'G', '615 Hill Road', 'F', '290-2556', 'R0017'),
('C0018', 'Cristiano', 'Ronaldo', 'G', '713 Magic Road', 'M', '382-7185', 'R0018'),
('C0019', 'Lioneil', 'Messi', 'K', '615 Well Street', 'M', '297-3809', 'R0019');
-- --------------------------------------------------------
--
-- Table structure for table `worker`
--
INSERT INTO `worker` (`Wrk_ID`, `Wrk_FirstName`, `Wrk_LastName`, `Wrk_Initial`, `Wrk_HireDate`, `Wrk_BirthDate`, `Wrk_Phone`, `Wrk_IRD_Num`, `Reg_ID`) VALUES
('W0010', 'Rhonda', 'Lewis', 'G', '2000-03-21', '1985-02-19', '855-2573', 'X993473419', 'R0010'),
('W0011', 'Rhett', 'VanDam', 'V', '2002-03-19', '1985-01-11', '994-1238', 'X993473500', 'R0011'),
('W0012', 'Anne', 'Jones', 'M', '2000-04-11', '1965-08-19', '894-9985', 'X9934735001', 'R0012'),
('W0013', 'John', 'Lange', 'P', '2000-04-12', '1975-05-17', '894-5680', 'X993473502', 'R0013'),
('W0014', 'Robert', 'Williams', 'D', '2004-05-19', '1978-03-02', '244-1672', 'X993473503', 'R0014'),
('W0015', 'Jeanine','Smith', 'K', '2005-06-19', '1988-07-04', '434-3381', 'X993473506', 'R0015'),
('W0016', 'Brown', 'James', 'G', '2006-03-19', '1982-06-28', '297-1232', 'X993473507', 'R0016'),
('W0017', 'Jorge', 'Diante', 'K', '2007-01-19', '1984-11-19', '222-2556', 'X993473508', 'R0017'),
('W0018', 'Paul', 'Wiesenbach', 'R', '2007-01-19', '1976-12-12', '389-7185', 'X993473509', 'R0018'),
('W0019', 'Leighla', 'Genkazi', 'W', '2007-01-19', '1989-04-30', '292-3809', 'X993473600', 'R0019');
-- --------------------------------------------------------
--
-- Dumping data for table `project`
--
INSERT INTO `project`(`Proj_ID`,`Proj_Desc`,`Proj_Est_Start`,`Proj_Est_Finish`,`Proj_Cost`,`Proj_Act_Start`,`Proj_Act_Finish`,`Proj_Act_Cost`,`Cli_ID`) VALUES
('P0010','Map Design','2015-04-01','2015-04-30',10000.00,'2015-04-05','2015-05-01',12000.50,'C0010'),
('P0011','Level Design','2015-03-02','2015-03-15',5000.00,'2015-03-02','2015-03-15',7500.00,'C0011'),
('P0012','Controlls Design','2015-04-20','2015-05-01',20000.00,'2015-04-21','2015-04-30',20500.00,'C0012'),
('P0013','Character Design','2015-04-15','2015-05-11',30000.00,'2015-04-15','2015-05-12',50000.00,'C0010'),
('P0014','Sound Design','2015-01-01','2015-04-30',5000.00,'2015-01-10','2015-04-30',97560.00,'C0013'),
('P0015','Game Play design','2015-03-20','2015-03-30',57000.00,'2015-03-20','2015-03-25',6500.00,'C0014'),
('P0016','Server Design','2015-04-01','2015-04-30',89000.00,'2015-04-01','2015-04-30',8900.00,'C0015'),
('P0017','Online Gamplay Design','2015-05-01','2015-05-15',10000.00,'2015-05-02','2015-05-16',10000.00,'C0016'),
('P0018','Software Design','2015-04-01','2015-04-15',15000.00,'2015-04-01','2015-04-15',14500.00,'C0019'),
('P0019','Game programming','2015-01-14','2015-05-01',125000.00,'2015-01-14','2015-05-01',125000.00,'C0019');
-- --------------------------------------------------------
--
--Dumping data for table `assignment`
--
INSERT INTO `assignment`(`Assign_ID`,`Assign_Desc`,`Assign_Est_Start`,`Assign_Est_Finish`,`Assign_Act_Start`,`Assign_Act_Finish`,`Wrk_ID`,`Proj_ID`) VALUES
('A0010','Design Game maps','2015-03-15','2015-04-20','2015-03-15','2015-04-20','W0010','P0010'),
('A0011','Design All levels of Game','2015-03-02','2015-03-15','2015-03-02','2015-03-15','W0012','P0011'),
('A0012','Design Controls For all Platforms','2015-05-01','2015-05-20','2015-05-02','2015-05-21','W0013','P0012'),
('A0013','Design All Character of Game','2015-04-05','2015-04-30','2015-04-05','2015-05-01','W0014','P0013'),
('A0014','Game music Soundtracks','2015-01-03','2015-04-25','2015-02-05','2015-04-30','W0015','P0014'),
('A0015','Virtual walk through of game','2015-03-15','2015-03-30','2015-03-15','2015-03-30','W0016','P0015'),
('A0016','MultiPlayer Game Design','2015-04-02','2015-04-28','2015-04-04','2015-04-30','W0017','P0016'),
('A0017','Online Hosting Design','2015-05-01','2015-05-16','2015-05-01','2015-05-30','W0018','P0017'),
('A0018','Game Interesction Design','2015-04-01','2015-04-15','2015-04-01','2015-04-15','W0011','P0018'),
('A0019','Game codes','2015-01-14','2015-05-05','2015-01-14','2015-05-05','W0019','P0019');
-- --------------------------------------------------------
--
----Dumping data for table `task`
--
INSERT INTO `task`(`Task_ID`,`Task_Desc`,`Task_Act_Start`,`Task_Act_Finish`,`Assign_ID`) VALUES
('T0010','Impliment Map Design','2015-03-15','2015-04-20','A0010'),
('T0011','Impliment game Levels','2015-03-02','2015-03-15','A0011'),
('T0012','Impliment Game Controls','2015-05-02','2015-05-21','A0012'),
('T0013','Impliment Game Characters','2015-02-05','2015-04-30','A0013'),
('T0014','Impliment Sound Design','2015-03-15','2015-03-30','A0014'),
('T0015','Impliment Gamplay designs','2015-04-04','2015-04-30','A0015'),
('T0016','Office Management Systems','2015-05-01','2015-05-30','A0016'),
('T0017','Impliment Multiplayer Gamplay','2015-04-01','2015-04-15','A0017'),
('T0018','Impliment Online Servers','2015-01-14','2015-05-05','A0018'),
('T0019','Impliment all Game Codes','2015-01-14','2015-05-05','A0019');
-- --------------------------------------------------------
--
----Dumping data for table `invoice`
--
INSERT INTO `invoice`(`Inv_ID`,`Inv_Amount`,`Inv_Due_Date`,`Proj_ID`) VALUES
('I0010',12000.50,'2015-04-30','P0010'),
('I0011',7500.00,'2015-03-31','P0011'),
('I0012',20500.00,'2015-04-30','P0012'),
('I0013',50000.00,'2015-05-30','P0013'),
('I0014',97560.00,'2015-05-30','P0014'),
('I0015',6500.00,'2015-04-30','P0015'),
('I0016',8900.00,'2015-05-30','P0016'),
('I0017',10000.00,'2015-05-30','P0017'),
('I0018',14500.00,'2015-04-30','P0018'),
('I0019',125000.00,'2015-05-15','P0019');
-- --------------------------------------------------------
--
----Dumping data for table `skill`
--
INSERT INTO `skill` (`Skill_ID`,`Skill_Desc`,`Skill_PayRate`) VALUES
('S0010','Map Designer',55.00),
('S0011','Level Designer',40.00),
('S0012','Game Designer',65.00),
('S0013','Graphics Designer',55.00),
('S0014','Music Producer',50.00),
('S0015','Project manager',98.50),
('S0016','Software Enginneer',50.00),
('S0017','IT Technician',40.50),
('S0018','Server Adminstrator',62.00),
('S0019','Network Enginneer',125.00);
-- --------------------------------------------------------
--
----Dumping data for table `employee_skill`
--
INSERT INTO `employee_skill`(`Skill_ID`,`Wrk_ID`) VALUES
('S0010','W0010'),
('S0011','W0011'),
('S0012','W0012'),
('S0013','W0013'),
('S0014','W0014'),
('S0015','W0015'),
('S0016','W0016'),
('S0017','W0017'),
('S0018','W0018'),
('S0019','W0019');
1) your first query need join conditions such as
where worker.wrkid= skill.wrkid and ....
2) your second query has an error, you need a comma between assignment and worker. Also join conditions are required.

Updating the database from 1.5.1.3 to 1.5.3.1 OpenCart

I'm trying to pass data from my table OpenCart version 1.5.1.3 to version 1.5.3.1. I'll be using a new theme and only a few of the modules used in the previous version, but do not want to lose the data records of customers, sales and products.
Bearing this in mind I guess the easiest way would be estrair the table to a SQL script (I used phpmyadmin), but there are some differences between the versions for the database schema and data so I am not able to pass data from a table another.
As an example I'll use the table "address" 1.5.1.3 version that has the following structure when exported by phpmyadmin:
INSERT INTO `address` (`address_id`, `customer_id`, `firstname`, `lastname`, `company`, `address_1`, `address_2`, `city`, `postcode`, `country_id`, `zone_id`) VALUES
(6, 6, 'Fulano', 'Silva', '', 'My Street, 455', 'Neighborhood 1', 'City 1', 'd9c 5t7', 30, 464),
(2, 2, 'Cicrano', 'Souza', '', 'My Avenue, 921', 'Neighborhood 2', 'City 2', 'd9c 5t7', 30, 464),
(4, 4, 'Beltrano', 'Cabrito', '', 'My Street 2, 191', 'Neighborhood 3', 'City 3', 'd9c 3t7', 30, 464);
And the database version 1.5.3.1 follows this model:
INSERT INTO `address` (`address_id`, `customer_id`, `firstname`, `lastname`, `apelido`, `company`, `company_id`, `tax_id`, `address_1`, `numero`, `address_2`, `complemento`, `city`, `postcode`, `country_id`, `zone_id`) VALUES
(6, 6, 'Fulano', 'Silva', '', '', '', '', 'My Street', '455', 'Neighborhood 1', '', 'City 1', 'd9c 5t7', 30, 464),
(2, 2, 'Beltrano', 'Cabrito', '', '', '', '', '', 'My Street 2', '191', 'Neighborhood 3', '', 'City 3', 'd9c 3t7', 30, 464);
This is repeated in several tables, now how do I get only the data you want from v1.5.1.3 to v1.5.3.1 using SQL or other simpler if any?
This is why the upgrade script is there. You can find out how to upgrade here