Hi All,
I am PHP programmer, I am using XAMPP software for programming. In MySQL the concept of referential integrety is not working. This is the following link which explains you my requirement. Pl go thru the following code in the link, it is not working.. http://www.informit.com/articles/art...seqNum=12&rl=1
Thank you.
Pavankumar P
3 1345
Heya, Pavankumar.
What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Heya, Pavankumar.
What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Hi,
This is what i am doing in the code. - CREATE TABLE parent
-
(
-
par_id INT NOT NULL,
-
PRIMARY KEY (par_id)
-
) ENGINE = INNODB;
-
-
CREATE TABLE child
-
(
-
par_id INT NOT NULL,
-
child_id INT NOT NULL,
-
PRIMARY KEY (par_id, child_id),
-
FOREIGN KEY (par_id) REFERENCES parent (par_id)
-
ON DELETE CASCADE
-
ON UPDATE CASCADE
-
) ENGINE = INNODB;
-
-
-
INSERT INTO parent (par_id) VALUES(1),(2),(3);
-
INSERT INTO child (par_id,child_id) VALUES(1,1),(1,2);
-
INSERT INTO child (par_id,child_id) VALUES(2,1),(2,2),(2,3);
-
INSERT INTO child (par_id,child_id) VALUES(3,1);
- +--------+
-
| par_id |
-
+--------+
-
| 1 |
-
| 2 |
-
| 3 |
-
+--------+
- +--------+----------+
-
| par_id | child_id |
-
+--------+----------+
-
| 1 | 1 |
-
| 1 | 2 |
-
| 2 | 1 |
-
| 2 | 2 |
-
| 2 | 3 |
-
| 3 | 1 |
-
+--------+----------+
2) This is what I am doing and want the result to be. - DELETE FROM parent WHERE par_id = 1;
-
-
SELECT * FROM parent;
- +--------+
-
| par_id |
-
+--------+
-
| 2 |
-
| 3 |
-
+--------+
- UPDATE parent SET par_id = 100 WHERE par_id =2;
-
-
SELECT * FROM parent;
- +--------+
-
| par_id |
-
+--------+
-
| 3 |
-
| 100 |
-
+--------+
- +--------+----------+
-
| par_id | child_id |
-
+--------+----------+
-
| 3 | 1 |
-
| 100 | 1 |
-
| 100 | 2 |
-
| 100 | 3 |
-
+--------+----------+
This is not happening with my Databse. Even though i do the same process i am getting, when i select the child table. - +--------+----------+
-
| par_id | child_id|
-
+--------+----------+
-
| 1 | 1 |
-
| 1 | 2 |
-
| 2 | 1 |
-
| 2 | 2 |
-
| 2 | 3 |
-
| 3 | 1 |
-
+--------+----------+
Pl give me the right code to get the same result.
Hi,
This is what i am doing in the code.
CREATE TABLE parent
(
par_id INT NOT NULL,
PRIMARY KEY (par_id)
) ENGINE = INNODB;
CREATE TABLE child
(
par_id INT NOT NULL,
child_id INT NOT NULL,
PRIMARY KEY (par_id, child_id),
FOREIGN KEY (par_id) REFERENCES parent (par_id)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE = INNODB;
INSERT INTO parent (par_id) VALUES(1),(2),(3);
INSERT INTO child (par_id,child_id) VALUES(1,1),(1,2);
INSERT INTO child (par_id,child_id) VALUES(2,1),(2,2),(2,3);
INSERT INTO child (par_id,child_id) VALUES(3,1);
SELECT * FROM parent;
+--------+
| par_id |
+--------+
| 1 |
| 2 |
| 3 |
+--------+
SELECT * FROM child;
+--------+----------+
| par_id | child_id |
+--------+----------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
+--------+----------+
2) This is what I am doing and want the result to be.
DELETE FROM parent WHERE par_id = 1;
SELECT * FROM parent;
+--------+
| par_id |
+--------+
| 2 |
| 3 |
+--------+
UPDATE parent SET par_id = 100 WHERE par_id =2;
SELECT * FROM parent;
+--------+
| par_id |
+--------+
| 3 |
| 100 |
+--------+
SELECT * FROM child;
+--------+----------+
| par_id | child_id |
+--------+----------+
| 3 | 1 |
| 100 | 1 |
| 100 | 2 |
| 100 | 3 |
+--------+----------+
This is not happening with my Databse. Even though i do the same process i am getting, when i select the child table.
SELECT * FROM child;
+--------+----------+
| par_id | child_id|
+--------+----------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
+--------+----------+
Pl give me the right code to get the same result.
Are you able to update value 2 to 100 in parent table?
This will not be allowed becuase you have dependent records in child table
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Darius |
last post by:
I was having an issue inserting data into a table in an I-Series DB2
database. The Insert statement itself is very simple:
Insert into Table1
select * from Table2
These two tables have...
|
by: Grant McLean |
last post by:
Hi
First a simple question ...
I have a table "access_log" that has foreign keys "app_id" and
"app_user_id" that reference the "application_type" and "app_user"
tables. When I insert into...
|
by: Greg Stark |
last post by:
There's another poster complaining about referential integrity checks causing
deadlocks. Unfortunately I've deleted the message so this response (and the
archives aren't responding) isn't going to...
|
by: Jimmie H. Apsey |
last post by:
Referential Integrity on one of our production tables seems to have been
lost. I am running Postgres 7.1.3 embedded within Red Hat
kernel-2.4.9-e.49.
Within that I have a table with referential...
|
by: Geisler, Jim |
last post by:
So, as far as I know, PostgreSQL does not have any way of verifying the loss
of referential integrity.
Are there any recommended methods or utilities for checking referential
integrity in a...
|
by: heyvinay |
last post by:
I have transaction table where the rows entered into the transaction
can come a result of changes that take place if four different tables.
So the situation is as follows:
Transaction Table...
|
by: Jeff North |
last post by:
I'm using Microsoft SQL Server Management Studio Express 9.00.2047.00
and expriencing problems with setting referential integrity on a link
table. The tables' schema is as follows:...
|
by: Paul Daly |
last post by:
I have the following xml file:
http://www.dalyconsulting.com/AutomaticUpdates/AutomaticUpdates.xml
and the following xsd file:
http://www.dalyconsulting.com/AutomaticUpdates/AutomaticUpdates.xsd...
|
by: ApexData |
last post by:
I have a 15 LookUp Tables tied to 15 ComboBoxes.
Some of the Tables contain 3 to 10 Recs, and a couple contain up to 50
Recs.
1- Is it a CommonPractice to link the field that gets the ComboBox...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |