db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dag.Wan...@Sun.COM (Dag H. Wanvik)
Subject Re: how to get names of column constraints ?
Date Thu, 08 May 2008 13:31:59 GMT
Maris Orbidans <maris.orbidans@ingg.com> writes:

> I know I can read constraint names from SYS.SYSCONSTRAINTS but can I get
> it from DatabaseMetaData?  
>
> I am trying to get ha-jdbc synchronization working with my derby
> database. The problem is that ha-jdbc reads INDEX_NAMEs from
> DatabaseMetaData  (with getIndexInfo) and assumes that column constraint
> has the same name and tries to drop it. 

Not sure what your exact problem is, can you post a standalone repro?
I tried the following which worked:

   st.execute("create table mytab (id int primary key, " + 
                                   "name varchar(50))");
   :
   s = con.createStatement();
   DatabaseMetaData dbm = con.getMetaData();
            
   rs = dbm.getIndexInfo(null, null, "MYTAB", false, false);

   while (rs.next()) {
       System.out.println("Table: " + rs.getString(3) + " Index: " + rs.getString(6));
       s.executeUpdate("alter table " + rs.getString(3) + " drop constraint "
                       + rs.getString(6));
   }

Dag

Mime
View raw message