473,473 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ON UPDATE CASCADE, is it correct that b remains NULL? even after update?

--------------
SELECT Version()
--------------

+--------------------+
| Version() |
+--------------------+
| 5.0.0-alpha-max-nt |
+--------------------+
1 row in set (0.00 sec)

--------------
DROP TABLE IF EXISTS A
--------------

Query OK, 0 rows affected (0.04 sec)

--------------
CREATE TABLE A
(
a CHAR(9) NOT NULL,
b CHAR(9),
c INT NOT NULL DEFAULT 1,
PRIMARY KEY (a),
INDEX (b, c)
)ENGINE = INNODB
--------------

Query OK, 0 rows affected (0.07 sec)

--------------
SHOW WARNINGS
--------------

Empty set (0.00 sec)

--------------
DESCRIBE A
--------------

+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| a | char(9) | | PRI | | |
| b | char(9) | YES | MUL | NULL | |
| c | int(11) | | | 1 | |
+-------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)

--------------
ALTER TABLE A
ADD FOREIGN KEY (b) REFERENCES A(a)
ON DELETE SET NULL
ON UPDATE CASCADE
--------------

Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0

--------------
SHOW WARNINGS
--------------

Empty set (0.00 sec)

--------------
DESCRIBE A
--------------

+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| a | char(9) | | PRI | | |
| b | char(9) | YES | MUL | NULL | |
| c | int(11) | | | 1 | |
+-------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)

--------------
SELECT * FROM A
--------------

Empty set (0.00 sec)

--------------
INSERT INTO A (a) VALUES ('a0')
--------------

Query OK, 1 row affected (0.03 sec)

--------------
INSERT INTO A (a) VALUES ('a1')
--------------

Query OK, 1 row affected (0.02 sec)

--------------
SELECT * FROM A
--------------

+----+------+---+
| a | b | c |
+----+------+---+
| a0 | NULL | 1 |
| a1 | NULL | 1 |
+----+------+---+
2 rows in set (0.00 sec)

--------------
UPDATE A SET a='updated' WHERE a='a0'
--------------

Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

--------------
SELECT * FROM A
--------------

+---------+------+---+
| a | b | c |
+---------+------+---+
| a1 | NULL | 1 |
| updated | NULL | 1 |
+---------+------+---+
2 rows in set (0.00 sec)

Bye
Jul 19 '05 #1
0 1180

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Fraser Hanson | last post by:
Hello, I have a table which has a foreign key relationship with itself. I want and expect my updates to cascade (deletes definitely cascade as expected) but instead I just get error 1217:...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
0
by: Morten Gulbrandsen | last post by:
-------------- SELECT Version() -------------- +--------------------+ | Version() | +--------------------+ | 5.0.0-alpha-max-nt | +--------------------+ 1 row in set (0.00 sec)
2
by: Gunnar Vøyenli | last post by:
Hi! For the sake of simplicity, I have three tables, Employee, Department and Work Employee >---- Department \ / \ / ^ ^ Work
7
by: Justin | last post by:
I am extremely new at SQL Server2000 and t-sql and I'm looking to create a simple trigger. For explanation sake, let's say I have 3 columns in one table ... Col_1, Col_2 and Col_3. The data type...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
3
by: beer | last post by:
Hello All I'm running 7.3.4-1 on a RH9 box. I'm having a problem with a trigger that seems to execute without actually performing the update that it should. The update returns true everytime...
5
by: wpellett | last post by:
I can not get the SQL compiler to rewrite my SQL UPDATE statement to include columns being SET in a Stored Procedure being called from a BEFORE UPDATE trigger. Example: create table...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.