efmarshall / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

H2 mode MySQL - 2 unique keys having the same name but defined in different tables will not be accepted #492

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please send a question to the H2 Google Group or StackOverflow first,
and only then, once you are completely sure it is an issue, submit it here.
The reason is that only very few people actively monitor the issue tracker.

Before submitting a bug, please also check the FAQ:
http://www.h2database.com/html/faq.html

What steps will reproduce the problem?
(simple SQL scripts or simple standalone applications are preferred)
1.Start h2 with MODE=MySQL
2.CREATE TABLE `test1` (
  `id` tinyint(3) unsigned NOT NULL,
  `name` varchar(50) NOT NULL,
  `description` varchar(250) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test2` (
  `id` tinyint(3) unsigned NOT NULL,
  `name` varchar(50) NOT NULL,
  `description` varchar(250) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

3.The returned error is: Caused by: org.h2.jdbc.JdbcSQLException: Constraint 
"NAME" already exists; SQL statement:
CREATE TABLE `test2` ( `id` tinyint(3) unsigned NOT NULL, `name` varchar(50) 
NOT NULL, `description` varchar(250) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY 
`name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 [90045-172]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
    at org.h2.message.DbException.get(DbException.java:171)
    at org.h2.message.DbException.get(DbException.java:148)
    at org.h2.command.ddl.AlterTableAddConstraint.tryUpdate(AlterTableAddConstraint.java:96)
    at org.h2.command.ddl.AlterTableAddConstraint.update(AlterTableAddConstraint.java:70)
    at org.h2.command.ddl.CreateTable.update(CreateTable.java:169)
    at org.h2.command.CommandContainer.update(CommandContainer.java:79)
    at org.h2.command.Command.executeUpdate(Command.java:235)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:181)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:156)
    at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.executeSqlScript(ResourceDatabasePopulator.java:186)
    ... 51 more

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system, file
system, and virtual machine?
- H2 v1.3.172 (SVN 4956)
- Windows 7 64bit
- java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

Do you know a workaround?
No

What is your use case, meaning why do you need this feature?

How important/urgent is the problem for you?

Please provide any additional information below.

Original issue reported on code.google.com by queeq...@gmail.com on 16 Jul 2013 at 12:50

GoogleCodeExporter commented 9 years ago
Yeah, this we're not going to fix because it has a trivial workaround.

Original comment by noelgrandin on 16 Jul 2013 at 8:36

GoogleCodeExporter commented 9 years ago
Can you, please, tell what is the workaround?

Original comment by oko...@malkosua.com on 12 Mar 2015 at 1:00

GoogleCodeExporter commented 9 years ago
There are two options:

  UNIQUE KEY (`name`)
and
  UNIQUE KEY `name2` (`name`)

Original comment by thomas.t...@gmail.com on 18 Mar 2015 at 6:47