MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 26th, 2003, 08:27 PM
mariaflor mariaflor is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 4 mariaflor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Foreign key in MySQL with Visual Basic doesn't work

I'm working in Visual Basic with MySql as data base server using innodb tables.

I made a foreign key between 2 tables with a restriction ON DELETE NO ACTION.
But when I delete a row on a parent table, the foreign key doesn't restrict the operation.

What can i do?

Thanks in advance.

Reply With Quote
  #2  
Old April 14th, 2003, 11:08 AM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Just some ideas off the top of my head.

Are you using:
  1. MySQL version 3.23.43b or higher?
  2. Are both tables InnoDB type?
  3. Have you created an index where both the Foreign Key and the referenced key are the first columns?
  4. The Foreign and referenced keys must be of the same column type (no type conversion can take place)
  5. Ensure none of the keys contain NULL as I believe this prevents InnoDB from checking the constraint.


Remember that InnoDB does not auto-create indexes. You must create these manually!

What syntax did you use to create the constraint?

Reply With Quote
  #3  
Old April 15th, 2003, 10:28 PM
mariaflor mariaflor is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 4 mariaflor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I made all the steps you wrote, but it doesn't work .

The syntax I used is:

ALTER TABLE cabfac
add constraint clientes
foreign key (codCliente)
references clientes (codCliente)
on delete no action
on update no action;

Reply With Quote
  #4  
Old April 16th, 2003, 12:45 AM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I can't check the syntax until I see the two tables you have referenced. Can you post the table structures (cabfac & clientes)?

Also, did you create the indexes BEFORE you made the Foreign Key constraints? That's an important step.

Reply With Quote
  #5  
Old February 9th, 2004, 10:22 AM
jjmiller jjmiller is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 jjmiller User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ANSI SQL-92 ON DELETE NO ACTION not supported by MySQL

Hi,

Not sure whether my reply will reach you as this thread is a bit ancient, but the problem you have encountered is due to a discrepancy in the way MySQL implements the NO ACTION option compared with the ANSI SQL-92 standard and most other relational database systems.

I have put a comment about this in Section 14.4.5.2 FOREIGN KEY Constraints in the MySQL online documentation, which reads as follows:
A further deviation from ANSI SQL-92 standards, at the time of writing, is the way MySQL treats the ON DELETE NO ACTION and ON UPDATE NO ACTION clauses, should you attempt to use them.

Under the ANSI SQL-92 standard, NO ACTION means "no action" in the sense that an attempt to delete or update a primary key value will not be allowed to proceed if there is a related foreign key value in the referenced table (Gruber, 2000:181). It is therefore the ANSI syntax for explicitly enforcing referential integrity and is supported by SQL Server 2000, Oracle 9 amongst other database systems.

However, in MySQL it should be noted that NO ACTION cannot be used for this purpose at present. In fact, including an ON DELETE NO ACTION or ON UPDATE NO ACTION clause in a MySQL/InnoDB CREATE TABLE statement *allows* the deletion or update of a primary key value regardless of whether it appears as a foreign key value in the related table.

If standard referential integrity restrcitions are required for InnoDB tables in MySQL, the ON DELETE RESTRICT/ON UPDATE RESTRICT syntax should be used instead. Or, alternatively, you can omit this clause entirely and the restriction will be applied as it is the default behaviour for a FOREIGN KEY...REFERENCES clause in a MySQL InnoDB table.

This point was confirmed recently by Victoria Reznichenko on the MySQL General Discussion List (URL), following a long thread on the subject in 2003 (URL).

According to Victoria, this discrepancy will be addressed in the future, so that NO ACTION becomes a synonym for RESTRICT and acts in the ANSI standard way. In the meantime, however, other users may find it useful to be aware of this discrepancy.

I hope this helps you, or anyone else who has been puzzled by this behaviour.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Foreign key in MySQL with Visual Basic doesn't work


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway