You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2014/07/16 21:53:04 UTC

[jira] [Commented] (DERBY-6668) Truncating a table may silently violate a deferred foreign key.

    [ https://issues.apache.org/jira/browse/DERBY-6668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14063997#comment-14063997 ] 

Knut Anders Hatlen commented on DERBY-6668:
-------------------------------------------

We should probably forbid TRUNCATE TABLE on a table referenced by a foreign key. At least that's how I understand SQL:2011, part 2, 14.10 <truncate table statement>, SR 4: "T shall not be identified by the name of the referenced table in any referential constraint descriptor."

> Truncating a table may silently violate a deferred foreign key.
> ---------------------------------------------------------------
>
>                 Key: DERBY-6668
>                 URL: https://issues.apache.org/jira/browse/DERBY-6668
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.11.0.0
>            Reporter: Rick Hillegas
>
> If you truncate a table which is referenced by a deferred foreign key, orphaned tuples are left in the foreign table. That is, the foreign key is violated but no exception is raised.
> Since table truncation involves changing conglomerate ids, this may be another case of derby-6665. Or this may be a new bug.
> The following script shows this behavior:
> {noformat}
> connect 'jdbc:derby:memory:db;create=true';
> create table tunique
> (
>   a int not null unique
> );
> create table tref
> (
>   a int references tunique( a ) initially deferred
> );
> insert into tunique values ( 1 );
> insert into tref values ( 1 );
> truncate table tunique;
> -- the unique table is empty
> select * from tunique;
> -- but the table which references it has a row
> select * from tref;
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)